Python Forum
Input a number with any number of digits and output it in reverse order of digits.
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input a number with any number of digits and output it in reverse order of digits.
#1
hi, i'm a python beginner. few months ago i've started learning python and it's getting interesting to me everyday. So, today i need some help on an interesting problem. "Write a program to reverse the digits of a input number and check if the both numbers are equal or not". Now, i've written a code for "Reverse the digits of a five digit number", but i want to generalize this code for any digit number input. so, how to do it? i've learned so far operators, functions, decision making statements, looping, exception handling and modules to some extent. here is the code i've written for a number upto five digits-

sum1=0
n=int(input("Please enter five digit Number:"))
num=n
a=n%10
n=n//10
sum1=(sum1+(a*10000))

a=n%10
n=n//10
sum1=(sum1+(a*1000))

a=n%10
n=n//10
sum1=(sum1+(a*100))

a=n%10
n=n//10
sum1=(sum1+(a*10))


a=n%10
n=n//10
sum1=(sum1+(a*1))

print("Number:",sum1)
if (num==sum1):
    print("Input number and the reverse number are equal")
else:
    print("Input number and the reverse number are not equal")
    
please provide your valuable suggestions.. Smile
Reply


Messages In This Thread
Input a number with any number of digits and output it in reverse order of digits. - by sarada2099 - Mar-09-2017, 05:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing the code line number arbiel 2 199 Jun-15-2024, 07:37 PM
Last Post: arbiel
  Finding the price based on industry and number of transactions chandramouliarun 1 1,072 Jun-04-2024, 06:57 PM
Last Post: marythodge4
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 269 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  intering int number akbarza 1 371 Apr-28-2024, 08:55 AM
Last Post: Gribouillis
Brick Number stored as text with openpyxl CAD79 2 751 Apr-17-2024, 10:17 AM
Last Post: CAD79
  If a set element has digits in the element tester_V 3 442 Mar-25-2024, 04:43 PM
Last Post: deanhystad
  [SOLVED] Pad strings to always get three-digit number? Winfried 2 488 Jan-27-2024, 05:23 PM
Last Post: Winfried
  Prime number detector Mark17 5 971 Nov-27-2023, 12:53 PM
Last Post: deanhystad
  Create X Number of Variables and Assign Data RockBlok 8 1,190 Nov-14-2023, 08:46 AM
Last Post: perfringo
  find the sum of a series of values that equal a number ancorte 1 590 Oct-30-2023, 05:41 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020