Pythondex
Python Programs

Adam Number Program In Python

Published June 26, 2023 by Jarvis Silva

In this tutorial we will create program in python to check adam number, An Adam number is a number for which the square of the number, when its digits are reversed and is equal to the square of the number obtained by reversing the digits.

For example the number 22 is an adam number because, the square of 22 is 484 and the reverse of 484 is also 484, So the reversed square and the square of the reversed number are equal thus making it an adam number.

So now let’s see how to create this program in python code.

Python Code To Check Adam Number


def is_adam_number(number):
    # Calculate the square of the number
    squared_number = number ** 2
    
    # Reverse the squared number
    reversed_squared_number = int(str(squared_number)[::-1])
    
    # Calculate the square of the reversed number
    square_of_reversed_number = int(str(number)[::-1]) ** 2
    
    # Check if the reversed square and square of the reversed number are equal
    return reversed_squared_number == square_of_reversed_number

# Example usage
number = int(input("Enter a number: "))
if is_adam_number(number):
    print(number, "is an Adam number.")
else:
    print(number, "is not an Adam number.")

As you can see in the code I have defined a function to check adam number, in the function we take the square of the number, reverse of the number then reverse of the squared number finally we check if they are equal.

You can run this program on your computer or use an online python compiler, after running it will ask you to enter a number then it will print if it is an adam number or not, below is an example output.


Enter a number: 2 3
3 is an Adam number.

As you can see we successfully created the program to check adam number, I hope you found this tutorial helpful, want more tutorials like this then join our telegram channel.

Here are some more python programs for you:

Thanks for reading, Have a nice day 🙂