-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_loops.py
More file actions
22 lines (16 loc) · 731 Bytes
/
04_loops.py
File metadata and controls
22 lines (16 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Exercise 04 — Loops.
Tutorial: https://pythonbeginner.help/learn/
TODO: using a loop,
1. Build `squares` = [0, 1, 4, 9, 16] (squares of 0..4).
2. Set `total` = the sum of the numbers 1..10 inclusive.
Run: python exercises/04_loops.py
"""
# --- your code below -------------------------------------------------------
squares = []
# TODO: loop over range(5) and append i * i to squares
total = 0
# TODO: loop over range(1, 11) and add each number to total
# --- self-check (don't edit) ----------------------------------------------
assert squares == [0, 1, 4, 9, 16], "squares should be the squares of 0..4"
assert total == 55, "total should be 1+2+...+10"
print("✅ Passed!", "squares:", squares, "total:", total)