Skip to content
Aabha AI Academy
Skip to reading

Python

02 Control Flow

Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.

# Reference answer. Attempt the exercise first.
minutes = 30
if minutes < 0:
    label = "invalid"
elif minutes == 0:
    label = "rest"
elif minutes < 30:
    label = "short"
else:
    label = "long"
total = 0
for value in [10, -5, 0, 25]:
    if value > 0:
        total += value
remaining = 3
countdown = []
while remaining > 0:
    countdown.append(remaining)
    remaining -= 1
assert label == "long" and total == 35 and countdown == [3, 2, 1]
print("Module 2 checks passed")

Download this source file