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.
Python program to reverse a number
n = int(input("please give a number : ")) print("before reverse your numeber is : %d" %n) reverse = 0 while n!=0: reverse = reverse*10 + n%10 n = (n//10) print("After reverse : %d" %reverse)
Also prepare these Python Programs:
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program