In this article, we will discuss the concept of the Python program to reverse the given number
In this post, we are going to learn how to find reverse of the given number in Python programming language
The program allows the user to enter a number and then it displays the reverse number of the given number using while loop in Python language
Program 1
#Pyton program to reverse a number using while loop Number=int(input("Pleaae enter a number for reverse: ")) #Ask input from the user print(" Entered number is: ",Number); Reverse=0;#declare and initialise variable while(Number>0): Reminder=Number %10 Reverse=(Reverse *10)+Reminder Number=Number//10; print(" Reversed number is %d: "%Reverse);
When the above code is executed, it produces the following result
Pleaae enter a number for reverse: 54321 (' Entered number is: ', 54321) Reversed number is 12345:
The program allows the user to enter a number and then it displays the reverse number of given number using the function in Python language
Program 1
#Python program to reverse a number using function def reverse_Num(Number): #Define a function Reverse=0 #declarae and initialize variable Reserve while(Number>0): Reminder=Number %10 Reverse=(Reverse *10)+Reminder Number=Number//10; return Reverse #return reverse value to function Number=int(input("Please enter a number: ")) Reverse=reverse_Num(Number)#Call the function print("The entered number is: %d" %Number) print("The reverse number is: %d" %Reverse)
When the above code is executed, it produces the following result
Please enter a number: 34567 The entered number is: 34567 The reverse number is: 76543
The program allows the user to enter a number and then it displays the reverse number of the given number using the recursion in Python language
Program 3
#Python program to reverse a number using recursion Reverse=0 #global variable def reverse_Num(Number): #Define a function global Reverse; if(Number>0): Reminder=Number %10 Reverse=(Reverse *10)+Reminder reverse_Num(Number//10); return Reverse #return reverse value to function Number=int(input("Please enter a number: ")) Reverse=reverse_Num(Number)#Call the function print("The Entered number is: %d" %Number) print("The reverse number is: %d" %Reverse)
When the above code is executed, it produces the following result
Please enter a number: 23456 The entered number is: 23456 The reverse number is: 65432
Suggested for you
Similar post
Java program to reverse the given number using loops
C++ program to reverse the given number using loops
C program to reverse the given number using loops
Java program to reverse the given String using loops
C++ program to reverse the given String using loops
C program to reverse the given String using loops
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…