bhylu.com

Advertisements

Code Challenge

Write a calculation for five 20-minute sessions with one comment explaining the unit and no comment that merely repeats the multiplication.

Understand the idea

Write your own solution before opening the worked answer. Predict the output from the supplied values, then compare the actual result. Check both an ordinary case and the boundary described below; a passing example is more useful when you can explain why it passes.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

Your task

Write a calculation for five 20-minute sessions with one comment explaining the unit and no comment that merely repeats the multiplication.

Show the worked solution
Python

# Durations are stored in minutes, not seconds.
session_minutes = 20
print(5 * session_minutes)

Check the result

The total is 100 minutes.

Test one more case

Convert the total to seconds in a separate statement and keep both units clear.