This phyton program requires you to accept from the user a three-digit integer (100-999), and prints the reverse of that integer. You can assume that the input is an integer, but should not assume it's in the right range. If it's not in the right range, print "Illegal input:" and the number. Here are three sample runs: Enter a three digit decimal integer: 234 The number in reverse is: 432 Enter a three digit decimal integer: 1345 Illegal input: 1345 Enter a three digit decimal integer: 555 The number in reverse is: 555 def printReverse(): < your code goes here >
def printReverse(n): if n>=100 and n<=999: result = 0 while (n > 0): result = result * 10 result += (n % 10) n = n // 10 print("The number in reverse is:",result) else: print("Illegal input:",n) # Testing n = int(input("Enter a three digit decimal integer: ")) printReverse(n)
Get Answers For Free
Most questions answered within 1 hours.