Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Square Each Number

Return a list where each number from the input has been squared.

Python practice10 minLoops & IterationBeginnerLast updated March 15, 2026

Problem statement

Write a function square_each(nums) that takes a list of integers nums and returns a new list where each integer is replaced by its square (n * n). Preserve the order. For an empty input list, return an empty list.

Task

Practice transforming list elements using loops and returning a new list.

Examples

Simple squaring

Input

square_each([1, 2, 3])

Output

[1, 4, 9]

Each element is squared: 1->1, 2->4, 3->9.

Input format

A single list of integers, e.g. [1, -2, 3].

Output format

A list of integers representing squares of the inputs, e.g. [1, 4, 9].

Constraints

Do not use list comprehensions for beginners who have not learned them yet; use an explicit loop. Aim for O(n) time.

Samples

Sample 1

Input

square_each([-1, 0, 5])

Output

[1, 0, 25]

Squares: (-1)^2=1, 0^2=0, 5^2=25.