![carvajalj2520](/avatars/41408.jpg)
carvajalj2520
21.04.2020 •
Computers and Technology
Your task is to break a number into its individual digits, for example, to turn 1729 into 1, 7, 2, and 9. It is easy to get the last digit of a number n as n % 10. But that gets the numbers in reverse order. Solve this problem with a stack. Your program should ask the user for an integer, then print its digits separated by spaces.
Solved
Show answers
More tips
- C Computers and Internet What is a URL? Everything You Need to Know About URL Addresses...
- C Computers and Internet Why is Yandex s robot Bless.yandex.ru Important?...
- F Food and Cooking Fresh and Easy Lemonade in 10 Minutes...
- S Sport How to wrap boxing hand wraps? Everything you need to know!...
- F Family and Home How to Sew Curtain Tapes: Best Tips from Professionals...
- A Animals and plants How to Grow Lime from a Seed: Simple Tips and Interesting Facts...
- C Computers and Internet How to Create a Folder on Your iPhone?...
- G Goods and services How to sew a ribbon: Tips for beginners...
- F Food and Cooking How to Make Mayonnaise at Home? Secrets of Homemade Mayonnaise...
- C Computers and Internet Which Phone is Best for Internet Surfing?...
Answers on questions: Computers and Technology
- C Computers and Technology Sarah is working on a project in which she needs to record all the extracurricular activities in her college. her college teaches five types of sports and three arts subjects. she...
- C Chemistry Why does steam produce more severe burns as compared to boiling water?...
- B Biology Give 3 examples where kinetic and potential energy is transformed into each other both ways....
- P Physics How do cranial nerves transmit information to the senses?...
- C Chemistry An ultraviolet wave traveling through a vacuum has a wavelength of 4.0 × 10–7 m. the wave’s frequency, written in scientific notation to two significant figures, is × 1014 hz....
- M Mathematics Write an equation to match each graph:...
- S Social Studies Hi, i have done poetry for school and people are saying that i should enter into a competition. i am in australia but...
- E English 10 zeitoun woke with the sun and crawled out of his tent. the day was bright, and as far as he could see in any direction the city was underwater. . he could only think of judgment...
- E English What are the effects of the imagery used in this poem? check all that apply. the reader can visualize the fields. the reader can imagine the humming sound of the bees. the reader...
- E English Which statement best describes the common experience of the colonists withthe american landscape...
Ответ:
stack = []
number = int(input("Enter a number: "))
while number > 0:
stack.append(number % 10)
number = int(number / 10)
while len(stack) > 0:
print(stack.pop(), end=" ")
Explanation:
Initialize an empty list to represent the stack
Get a number from the user
Create a while loop that iterates through the given number and append its last digit to stack
When the first loop is done, your stack is filled with the digits of the given number
Create another while loop that iterates through your stack and prints its elements, digits of the number, separated by spaces
Ответ: