Perfect square numbers in python
08:41 16 Jan 2026

is this how you reads an integer n and prints out all the positive perfect square

numbers that is not larger than n

n = int(input())

i = 1
result = []

while i * i <= n:
    result.append(i * i)
    i += 1

print(", ".join(map(str, result)))

Logic

  • Start from 1

  • Square i until i*i > n

  • Print all squares ≤ n

python