Python Practice › Function Programs › Program 12
Squares of 1 to 10
Write a Python function that creates and prints a list of the squares of 1 to 10.
Output
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Approach
- Build the list, print it and return it.
Solution
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]
Learn the concept
New to this topic? Read the lesson, then come back.