Problem 183990 · easy · Phase 01 Prerequisites & Setup

Perfect Squares Up to a Limit

loops · while · lists · sequences

Write squares_up_to(n) that returns the list of perfect squares 1, 4, 9, 16, ... that are less than or equal to n, in increasing order. If no square fits, return an empty list.

Examples

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

Input:  n = 0
Output: []

Constraints

  • -10**6 <= n <= 10**6

Goals

  • Generate a sequence with a while loop that stops at a limit
  • Collect the generated values in a list
Starting Python…