Part of the series

Several example codes

~1 min read • Updated Oct 11, 2025

Program Overview

This Python program defines a method named isSquare that determines whether a given number is a perfect square.
It then checks a list of sample numbers to identify which ones are square numbers.


Python Code:


import math

def isSquare(n: int) -> bool:
    if n < 0:
        return False
    root = int(math.sqrt(n))
    return root * root == n

# Sample numbers
numbers = [12, 49, 1, 81]

# Check and print results
for num in numbers:
    if isSquare(num):
        print(f"{num} is a perfect square.")
    else:
        print(f"{num} is not a perfect square.")

Sample Output:


12 is not a perfect square.
49 is a perfect square.
1 is a perfect square.
81 is a perfect square.

Step-by-Step Explanation:

- The function isSquare uses math.sqrt to find the square root of the number
- It converts the result to an integer and squares it again
- If the squared value equals the original number, it is a perfect square
- The program checks each number in the list and prints the result


Written & researched by Dr. Shahin Siami