Unit 1 ยท Lesson 6

Build Interactive Programs

Plan, build, run, check, and improve one step at a time.

๐Ÿ” Find the First Broken Link

Which line fails first when the user enters 120 and 2.5?

broken_speed.py

๐Ÿ” The Build Cycle

Small checkpoints keep the program understandable.

1

Plan

Write IPO, variables, and the formula.
2

Build Small

Add one working part.
3

Run

Execute the current version.
4

Check

Compare what happened with what you expected.

When the checkpoint works, extend the program by one more small part.

๐Ÿ—บ๏ธ Plan Before Code

Turn the speed report requirement into a concrete plan.

I

Input

Distance in km and time in hours

P

Processing

Divide distance by time

O

Output

Average speed with km/h

Average Speed
v=dtv = \dfrac{d}{t}

โŒจ๏ธ Read One Value

Verify one prompt, conversion, and stored value.

speed_step_1.py
Console Output
Distance in km: 120 120.0

โŒจ๏ธ Read Both Values

Confirm both inputs before adding the formula.

speed_step_2.py
Console Output
Distance in km: 120 Time in hours: 2.5 120.0 2.5

๐Ÿ” What Should You Check?

The program can read both values without an error.

๐Ÿ“

Question

You have just completed the input checkpoint.

What evidence should you collect before adding the formula?

๐Ÿงฎ Add the Formula

Calculate and inspect the raw result first.

speed_step_3.py
Console Output
Distance in km: 120 Time in hours: 2.5 48.0

๐Ÿ’ฌ Present the Result

Replace temporary checks with clear final output.

speed_report.py
Console Output
Distance in km: 120 Time in hours: 2.5 Average speed: 48.0 km/h

๐Ÿงช Test with a Purpose

Each test should answer a different question.

12

Normal Value

Does the main calculation work?

59 / 60

Grouping Boundary

Use values around a change, such as 59 and 60 seconds.

2.5

Decimal Value

Did you choose float() where needed?

A program running without an error is not enough. Check whether the result is correct.

๐Ÿ” Choose the Stronger Test Set

Which set gives the best evidence for a ticket total program?

๐Ÿ“

Question

The program reads a decimal ticket price and a whole-number quantity.

A: (10, 2), (10, 2), (10, 2)
B: (18.5, 4), (0, 3), (7.25, 1)
C: (5, 1)

๐Ÿท๏ธ Keep Meaning Consistent

Names, prompts, units, and output should describe the same data.

clear_speed_report.py
km

Carry the Unit

The prompt and output both identify km, hours, and km/h.

name

Carry the Meaning

Variable names make each calculation readable.

๐Ÿ“ Homework

Complete it on time and submit it before the deadline.

๐Ÿ”– Summary

Key takeaways from this lesson.

Plan

Identify IPO, variables, conversions, and the formula before coding.

Run Early

Build the smallest working version and run after each addition.

Narrow the Error

The newest small change is the first place to inspect.

Test with Purpose

Compare normal, boundary, and decimal results with expectations.

๐Ÿงญ Task 1: Put the Steps in Order

Turn a list of actions into a reliable build process.

Your Goal

1. Order the seven actions shown below. Keep a Run and Check step after each new program part.

2. Write the ordered actions as comments in a new Python file.

3. Add one short note under each checkpoint describing what you would verify.

Actions
Add Output
Run and Check
Plan
Run and Check
Add Processing
Run and Check
Read Input

๐Ÿ› ๏ธ Task 2: Repair the Connections

Fix one connection, run again, and then continue.

Your Goal

1. Run the program and identify the first failing connection.

2. Fix only that issue, then run the program again.

3. Repeat until the calculation and output both work.

4. Test with a decimal ticket price.

Example Code

๐ŸŽŸ๏ธ Task 3: Event Ticket Total

Build a complete program through at least three checkpoints.

Your Goal

1. Plan the IPO, variables, conversions, and formula.

2. Build the input, processing, and output in separate checkpoints.

3. Ask for an event name, ticket price, and ticket quantity.

4. Test one whole-number price and one decimal price.

Example Output
Event name: Science Fair
Ticket price: 18.5
Number of tickets: 4
4 tickets for Science Fair cost 74.0 yuan.

๐Ÿฅฃ Task 4: Scale a Recipe

Translate a ratio formula and verify a decimal result.

Your Goal

1. Plan the IPO and choose clear variable names for servings and ingredient amount.

2. Ask for original servings, target servings, and the original amount in grams.

3. Translate the formula below into Python. In the formula, a means amount and s means servings.

4. Run after each checkpoint and test a result that contains a decimal.

Scaled Ingredient Amount
anew=aoriginalร—stargetsoriginala_{new} = a_{original} \times \dfrac{s_{target}}{s_{original}}
Example Output
Original servings: 4
Target servings: 10
Original amount in grams: 300
For 10 servings, use 750.0 g.

โฑ๏ธ Task 5: Time Converter

Use boundary tests to verify complete groups and a remainder.

Your Goal

1. Ask for a whole number of total seconds.

2. Calculate complete minutes with // and remaining seconds with %.

3. Print the original value and converted result with an f-string.

4. Test with 59, 60, and 125, then compare each result with your expectation.

Example Output
Total seconds: 125
125 seconds = 2 minutes and 5 seconds.
01 / 19