Write a program to reverse a number entered by the user. Call your program int_reverser.py. Suggested approach:
a. Write an expression for the number of digits. This is the log in base 10 , math.log100, but it should be a whole number.
b. Write a loop to keep dividing the number by 10 and printing the remainder.
c. Add an accumulator variable for the result. Keep multiplying the result by 10 and adding the remainder. Example usage:
Integer reverer
Integer: 1234
4321
import math n = int(input("Enter number: ")) numberOfDigit = math.log10(n) if n<=10: result = n else: result = 0 i = 0 while i<=numberOfDigit: result += n % 10 result = result * 10 n = n // 10 i+=1 result = result//10 print(result)

Enter number: 1234
4321
Hope this is helpful. Write back to me in case you need help with your python task. I generally reply back within 24 hours. You can connect with me on Whatsapp also: +918602715108
Comments
Post a Comment