Python program to reverse a number with explanation
In this tutorial we are going to learn how to write a program to reverse the digits of a given number in Python programming language.
So Lets Begin:
Before directly moving on the writing reverse program in C first you should understand the logic behind it.
Suppose if someone gives input 123 and our program should give output 321.
Logic behind it is, first our target is to take last number and store it and then second last and append it with previous one and then rest.
Following is sample python code.
8 n = int(input("please give a number : "))
9
10 reverse = 0
11 while n!=0:
12 reverse = reverse*10 + n%10
13 n = (n//10)
14 print("After reverse : %d" %reverse)