Code Snippets

  

Linux & UNIX Source Code

  

Python Source Code



Automorphic Number

Checks whether a given number is automorphic or not.

Submitted By: captainhampton
Actions:
Rating:
Views: 1,205

Language: Python

Last Modified: September 2, 2010
Instructions: Feed any integer n into the function for validation or negation as to whether it is an automorphic number.

Snippet


  1. #An automorphic number (Circular Number) is a number whose square
  2. #ends in the same digits as the number itself. As an example
  3. #5^2 = 25, 76^2 = 5776 etc.
  4.  
  5. def Automorphic (n):
  6.         auto = str(n**2)
  7.         n = str(n)
  8.         count = -1
  9.         for i in range(len(n)):
  10.                 if auto[count] == n[count]:
  11.                         count -= 1
  12.                         return True
  13.                 return False
  14.  
  15. print Automorphic(5)                #Automorphic Number
  16. print Automorphic(25)                #Automorphic Number
  17. print Automorphic(4)                #Not Automorphic Number
  18.  

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.