In: Computer Science
Write a python code to Design and implement a function with no input parameter which reads a number from input (like 123). Only non-decimal numbers are valid (floating points are not valid). The number entered by the user should not be divisible by 10 and if the user enters a number that is divisible by 10 (like 560), it is considered invalid and the application should keep asking until the user enters a valid input. Once the user enters a valid input, the program calculates the reverse of the input number (for 153, the reverse is 351) and prints the result and returns the results.Do not use try and except. Use Main function.
Python code:
#defining function which returns the reverse of number
def reverse():
#asking for number
num=input("Enter a number: ")
#infinite loop till valid number is
entered
while True:
#checking if the number
is floating point
if("." in num):
#asking for valid number
num=input("Enter a valid number: ")
else:
#converting number to integer
num=int(num)
#checking if number is divisible by 10
if(num%10==0):
#asking for valid number
num=input("Enter a valid number: ")
else:
#printing reversed number
print("Reversed number is "+str(num)[::-1])
#returning reversed number
return str(num)[::-1]
def main():
#printing Returned value
print("Returned value is "+reverse())
if __name__ == "__main__":
main()
Screenshot:
Input and Output: