Problem 191877 · easy · Phase 01 Prerequisites & Setup

Build the Squares

lists · loops · append

Write build_squares(n) that returns a new list containing the squares of the numbers 1 through n, in order: [1, 4, 9, ...]. If n is zero or negative, return an empty list.

Examples

Input:  n = 4
Output: [1, 4, 9, 16]

Input:  n = 0
Output: []

Constraints

  • -100 <= n <= 5000

Goals

  • Start from an empty list and grow it with append
  • Use range to loop from 1 to n
Starting Python…