num=int(input("enter a number:" ))
a=0
while (num>0):
b=num
a=a*10 b
num=num//10
print("reverse of num", "is", a)
this is the code , I want to reverse a number, but when I enter a number and press enter I receive multiple answers, and the last answer is the only one I want to get.here is a pic for the problem I am having
CodePudding user response:
Just put the print statement outside the while
num=int(input("enter a number:" ))
a=0
while (num>0):
b=num
a=a*10 b
num=num//10
print("reverse of num", "is", a)
CodePudding user response:
You can easily solve this if you don't (immidiatly) convert the number to an int.
num = input("enter a number:" )
reversed_num = int(num[::-1])
print("reverse of num", "is", reversed_num)