Exercises

Trace names, predict numerical expressions, choose readable identifiers, build labelled reports, and repair one text-and-number mismatch.

Trace and Predict

Q1. Trace names and output

What does this program display?

Choose one

Select one choice, then check.

HintSeparate remembered values from output

The first three lines change names but do not display anything.

SolutionThe current values are 21 and 41

The second line reassigns reading to 21. total then becomes 41, and the two print calls display those values in order.

Not attempted
Review

Not marked done.

Q2. Predict a numerical result

Evaluate (23 - 20) ** 2 + 10 // 4 + 10 % 4 before running it.

Compute it first, then check your number.

HintCalculate three smaller results

Find (23 - 20) ** 2, 10 // 4, and 10 % 4 separately.

SolutionThe result is 13

The three parts are 9, 2, and 2. Their sum is 13.

Not attempted
Review

Not marked done.

Q3. Choose a readable name

Which valid name best describes a temperature's distance from the chosen reference value?

Choose one

Select one choice, then check.

HintCheck both rules and meaning

A name cannot begin with a digit, and a one-letter name hides the value's role here.

SolutionUse distance_from_reference

The name follows ordinary Python style and remains understandable without a separate comment.

Not attempted
Review

Not marked done.

Build and Repair Reports

Q4. Complete a labelled report

Complete the final line so the program displays Mean: 20.5 °C.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintUse one decimal place

Put {mean:.1f} and {unit} inside an f-string.

SolutionFormat the mean inside the report
print(f"Mean: {mean:.1f} {unit}")
Not attempted
Review

Not marked done.

Q5. Repair a numerical input

The count arrived as text. Repair the program so it displays mean: 20.5.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintInspect the count's meaning

The characters "4" genuinely represent a whole-number count, so int() is appropriate.

SolutionConvert the count once
count = int(count_text)
Not attempted
Review

Not marked done.

Q6. Construct a rainfall report

The rainfall readings are 3, 5, 4, and 8 millimetres. Replace the starter values and final report so the program displays Mean rainfall: 5.0 mm.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintKeep calculation and report roles distinct

Use 3, 5, 4, and 8 as the reading values. Then display mean with {mean:.1f} inside an f-string.

SolutionName, calculate, and report
Not attempted
Review

Not marked done.

Pause and reflect

Which exercises were difficult, what mistake pattern did you notice, and what should you practice again? The note stays with this exercise set.

0 of 6 exercises marked done

Review

Not marked done.