Untitled
unknown
plain_text
2 years ago
371 B
6
Indexable
def square_numbers(n):
# create an empty list to store the squares
squares = []
# calculate the square of each number from 1 to n
for i in range(1, n + 1):
squares.append(i ** 2)
# return the list of squares
return squares
# call the function to calculate the square of the first 5 natural numbers
print(square_numbers(5))
Editor is loading...
Leave a Comment