Q:

Write a Program to extract each digit from an integer in the reverse order.

belongs to collection: Python Basic Exercises for Beginners

-1

Write a Program to extract each digit from an integer in the reverse order.

For example, If the given int is 7536, the output shall be “6 3 5 7“, with a space separating the digits.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution: Use while loop

number = 7536
print("Given number", number)
while number > 0:
    # get the last digit
    digit = number % 10
    # remove the last digit and repeat the loop
    number = number // 10
    print(digit, end=" ")

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

using python, Calculate income tax for the given i... >>
<< Create a new list from a two list using the follow...