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

30th Nov 2022, 7:07 AM
Anonymous
Anonymous - avatar
4 Answers
+ 1
See it's python alright n = int(input()) m = str(n) print (int(m[::-1]))
30th Nov 2022, 6:25 PM
Hula
+ 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()
1st Dec 2022, 11:54 AM
Lothar
Lothar - avatar
+ 3
Anonymous See this code it will solve your code https://code.sololearn.com/ctnysndMuv20/?ref=app
30th Nov 2022, 7:08 AM
Sâùtôsh
Sâùtôsh - avatar
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)
30th Nov 2022, 7:13 AM
Anonymous
Anonymous - avatar