Input a number and check if it is an automorphic number or not using a function in Python
Function - Question 10
In this question, we will see how to input a number and check if it is an automorphic number or not in Python programming using a function. To know more about function click on the function lesson.
Q10) Write a program in Python to input a number and check if it is an automorphic number or not using a function.
A number N is said to be automorphic, if its square ends in N for example 5 is automorphic, because 52=25, which ends in 5, 25 is automorphic, because 252=625, which ends in 25.
def automorphic(num): x=1 t=num while t>0: x=x*10 t=t//10 s=num*num # square of the number if s%x==num: return 1 return 0 # main program n=int(input('Enter a number ')) if automorphic(n)==1: print('Automorphic Number') else: print('Not Automorphic Number')
Enter a number 25 Automorphic Number