Chapter 0 quiz

Ten questions to bring the chapter together.

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

Question 1

Print the types of count, price, and code. Then print 4 tickets cost HK$10.00 using an f-string and a calculated bill. Keep code as text.

Write your answer, then run it.

Question 2

You have 29 items. A box holds 6. Print full boxes and leftovers. Each full box costs HK$3 to pack; each leftover item costs HK$1. Print the total packaging charge.

Write your answer, then run it.

Question 3

Clean the item name, convert numeric text, and print BOOK: 2 items, HK$37.50.

Write your answer, then run it.

Question 4

A student gets a discount only if the bill is at least HK$100 AND they have a student card. Print Discount or No discount. Test the given boundary, then bill=99.

Write your answer, then run it.

Question 5

Loop over the scores. Calculate the total and the number scoring at least 60. Print the average with one decimal place, then the passing count. Do not hardcode the list length.

Write your answer, then run it.

Question 6

Define a function discounted_bill(price, quantity, rate) that returns the product cost after a discount. Print bills for (20, 3, 0.1) and (12.5, 2, 0) with two decimals.

Write your answer, then run it.

Question 7

Start at HK$2000 and apply rates [0.05, -0.10, 0.02]. Print the balance after each step. Add a comment stating one omitted real-world cost.

Write your answer, then run it.

Question 8

A ChatGPT suggestion says the code below computes the average. Fix its formula, print the correct average, and add a comment with an independent hand calculation. Do not accept the suggestion only because it runs.

Write your answer, then run it.

Question 9

Start with prices [12.5, 8.0, 9.5]. Add 5.0 at the end and remove the item whose value is 8.0. Create a separate list with the remaining prices in ascending order. Print the updated original list, the ordered list, and the average price with two decimal places. The original must keep its updated order.

Write your answer, then run it.

Question 10

Define days_to_goal(start, daily_saving, goal), returning how many daily deposits are needed to reach or exceed the goal. All inputs are in HK dollars and daily_saving is positive. Count deposits until the target is met, without supplying a fixed repetition count. Print the results for (50, 15, 200) and (200, 15, 200). Include a hand-check comment. This model has no interest or spending.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.