Chapter 1 · Section 1 practice

Lists and Comprehensions

Work from question 1 to 10. Edit your Python box, click Run Code, review the result, then click Submit attempt. Reference answers unlock after all ten attempts are submitted. This records completion, not correctness. Each box runs independently. Progress is saved in this browser.

Submitted: 0 / 10

1. Read the first item

Warm-up. Print the first dish and the number of dishes.

Write your answer, then run it.

2. Select a range

Warm-up. Print the last dish, then a list containing only Char Siu and Toast.

Write your answer, then run it.

3. Add and remove

Warm-up. Append Toast; pop the first item. Print the removed item and remaining list.

Write your answer, then run it.

4. Raise every price

Build your skills. Use a comprehension to add HK$3 to every price. Print the new list.

Write your answer, then run it.

5. Keep affordable dishes

Build your skills. Keep prices strictly below HK$50 using a comprehension.

Write your answer, then run it.

6. Classify prices

Build your skills. Print one Premium label for prices at least 50, otherwise Regular.

Write your answer, then run it.

7. Calculate paired revenues

Build your skills. Use zip to pair counts with bills. Print revenues and their total.

Write your answer, then run it.

8. Check unequal inputs

Challenge. Print whether lengths match, then list(zip(counts, bills)). Explain the missing record in a comment.

Write your answer, then run it.

9. Filter and transform

Challenge. Apply a HK$5 discount only to original prices at least 50. Print discounted prices; exclude all others.

Write your answer, then run it.

10. Explain a price policy

Challenge. Raise each price by HK$2, label updated prices Premium at 50 or above, and print both lists. Explain why updated prices must be used.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.