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.
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
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.
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