Automorphic Number In Given Range In Python

         

        Automorphic Number In Given Range 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:

    def isAutomorphic(num):
      #square of the number
      sqr = num**2
      #number of digits in num 
      n = len(str(num))
      #last n digits of the square
      last = sqr%pow(10,n)
      return last == num


    n1=int(input("Enter Starting Value"))
    n2=int(input("Enter Ending Value")) 
    #loop through all the numbers in the range
    for x in range(n1,n2):
      if isAutomorphic(x):
        print(x,end=' ')

    OutPut:
    Enter Starting Value1
    Enter Ending Value100
    1 5 6 25 76 




    For More Information Visit: http://msktutorials.com/












    No comments:

    Post a Comment