Chapter 0 · Section 7 practice

Check and Explain Your Work

Work from question 1 to 10. Write your code, click Run Code, review the result, then click Submit attempt. An attempt may be wrong: reference answers become available after you submit all 10. Each Python box is independent. Submission progress is saved in this browser.

Submitted: 0 / 10

1. Fix a name

Warm-up. Python names are case-sensitive. Repair the misspelled name so this prints 20.

Write your answer, then run it.

2. Fix mixed types

Warm-up. The intended numeric answer is 350. Convert the text input before adding.

Write your answer, then run it.

3. Find the missing colon

Warm-up. Repair the syntax so a score of 65 prints Pass.

Write your answer, then run it.

4. Repair indentation

Build your skills. Put the first print inside the if block and keep Done outside. The result at False should be only Done.

Write your answer, then run it.

5. Compare rather than assign

Build your skills. The condition should test whether the label equals YES. Repair the operator, then print Approved at the given input.

Write your answer, then run it.

6. A calculation can run and be wrong

Build your skills. The desired profit is revenue minus cost, not their sum. Fix the code, print the result, and add a comment explaining the mistake.

Write your answer, then run it.

7. An excluded endpoint

Build your skills. The program must visit years 1, 2, 3, and 4. Fix the range and print all four years.

Write your answer, then run it.

8. A total that keeps resetting

Challenge. Move the initialization so all three prices contribute to the final total. Print the correct total.

Write your answer, then run it.

9. Choose the right conversion

Challenge. A suggested fix uses int for a decimal price and still fails. Repair the conversion, print the bill with two decimals, then test price_text=“8.75” yourself.

Write your answer, then run it.

10. Find a units mistake

Challenge. The input price is 250 HK cents per item, and 3 items are bought. Repair the conversion and variable name so the printed bill is in HK dollars. Add a comment with a hand check.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.