English

Write a program to find the reverse of that number.

Advertisements
Advertisements

Question

Write a program to find the reverse of that number.

Code Writing
Advertisements

Solution

Form the reverse by appending the last digit of the number at each step.

n = int(input("Enter any number: "))
reverse = 0

while n > 0:
    reverse = reverse * 10 + n % 10
    n //= 10

print("Reverse number is", reverse)
shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Review of Phython - EXERCISE [Page 27]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 1 Review of Phython
EXERCISE | Q 21. | Page 27
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×