0
How to make a program that display the reverse of the number entered.
For example, if user enters 12345, then program should return (54321).
4 Answers
+ 1
See it's python alright
n = int(input())
m = str(n)
print (int(m[::-1]))
+ 4
in some cases the use of str() function is not allowed. then we can need an algorithm that can handle the task with integer values.
num = int(input())
#return 0 # return can only be used from within functions
rev = 0 # a variable to store calculation results
while num > 0:
rem = num % 10 # this returns the right most digit which is the remainder of a modulo division **1
num = num // 10 # this cuts off the rith most digit **2
rev = rev * 10 + rem # update the output value
print(rev)
**1 and **2 can also be done in one step by using the python built-in function divmod()
+ 3
Anonymous
See this code it will solve your code
https://code.sololearn.com/ctnysndMuv20/?ref=app
0
SùñtÎsh
num=int (input("Please Enter the number: "))
x = num
return 0
while num>0:
num=num // 10
rev-rev*10+rem is rev)
print ("Reverse of a entered number, " x", "is = ",rev)