check whether the given number is Automorphic or not In Python

        

         check whether the given number is Automorphic or not.

 In Python


An automorphic number is a number whose square ends in the same digits as the 

original number itself. Examples: 5, 76, etc.



Program:

    num = int(input("Enter a number:"))

    #find number of digits in num 
    n = len(str(num))
    #compute square
    sqr = num**2
    #Extract last n digits from the square
    last = sqr%pow(10,n)
    #compare last n digits with the input number
    if last == num:
      print("Automorphic Number")
    else:
      print("Not an Automorphic Number")

    OutPut:
    Enter a number: 
    5
    Automorphic Number


    Enter a number:25
    Automorphic Number

    Enter a number:26
    Not an Automorphic Number

















    No comments:

    Post a Comment