I try to get reverse number in python but it doesn't work

Question:

I try to write a program that asks the user to enter a number. Then he shows him a copy of this number, but in reverse using python this is my code

def booking_revers (n):
  booking = 0            
  while n > 0:
    booking = (booking * 10)+ (n % 10)
    n // 10
  return booking

booking_revers (1235)

but when I try to run in vscode, I didn’t get any result in the terminal.

enter image description here

Asked By: Moh Sa

||

Answers:

def booking_revers (n):
  booking = 0            
  while n > 0:
    booking = (booking * 10)+ (n % 10)
    n = n // 10 #update the n variable lol
  return booking

you can just reverse the number:

def booking_reverse(n):
    str_n = str(n)
    print(str_n[::-1])

booking_reverse(10)
booking_reverse(100)
booking_reverse(12345)

would output:

01
001
54321
Answered By: Jacob Kearney
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.