Skip to Main Content
Blog

Print perfect squares in Python

Print perfect squares in Python

Enter number: 12
1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144,
def main():
	"""
	Prints the perfect squares from 1 to n.
	"""

	num = int(input("Enter number: "))
	for i in range(1, num + 1):
		squared = i * i
		print(squared, end=", ")


if __name__ == "__main__":
	main()