Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
371 B
1
Indexable
Never
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))
Leave a Comment