Squares of 1 to 10

EasyFunction Programs · 12 of 39

Write a Python function that creates and prints a list of the squares of 1 to 10.

Advertisement
Output
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Approach

  1. Build the list, print it and return it.

Solution

Python
def squares(n=10):    result = [i * i for i in range(1, n + 1)]    print(result)    return result squares()
Output
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs