Untitled

 avatar
unknown
plain_text
a year ago
371 B
4
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