Check Automorphic Number in Python

Check whether a number is automorphic (its square ends with the same digits).

BeginnerConditional ProgramsExample 11 of 20
check-automorphic-number.py
1# Program to check automorphic number
2
3num = int(input("Enter an integer: "))
4
5square = num * num
6if str(square).endswith(str(num)):
7 print(num, "is an automorphic number")
8else:
9 print(num, "is not an automorphic number")

Output

Enter an integer: 25
25 is an automorphic number

What's going on

An automorphic number appears at the end of its own square (e.g., 25 → 625).

We convert both to strings and use endswith() to test the property.

After this program

If the idea is still fuzzy, read Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 conditional programs, or see every topic on Python exercises.