Write the python code to input a number and print the reverse of the number by using for loop (not while or any other loop and it is not on google so please dont copy them)
Answers
Answered by
3
Question:-
Write a Python code to input a number and print the reverse of the number using for loop.
Program:-
Here is your program written in python.
------------------------------------
n=int(input("Enter a number: ");
s=0
string=str(n)
x=len(string)
for I in range (0,x, 1):
d=n%10
s=s*10+d
n=n//10
if n==0:
break
print("The reversed number is: ",s)
------------------------------------
First of all, we will calculate the number of digits of the number(say n) . Then a loop will run(for n times) that will reverse the number.
After reversing, the number is printed.
But if the user enter 100 then the output is 1(not 001)
Similar questions