Advertisement
immanual1

reversenum.py

Jan 13th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. def reverse_number(n):
  2. reversed_num = 0
  3. while n > 0:
  4. digit = n % 10
  5. reversed_num = reversed_num * 10 + digit
  6. n //= 10
  7. return reversed_num
  8.  
  9. num = int(input("Enter a number: "))
  10. reversed_num = reverse_number(num)
  11. print("Reversed number:", reversed_num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement