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.
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.
Question 1
count = 4
price = 2.5
code = "0042"
print(type(count))
print(type(price))
print(type(code))
print(f"{count} tickets cost HK${count * price:.2f}")Expected output
<class 'int'>
<class 'float'>
<class 'str'>
4 tickets cost HK$10.00A count, a price, and an identifier have different types and purposes.
Question 2
items = 29
capacity = 6
full_boxes = items // capacity
leftover = items % capacity
charge = full_boxes * 3 + leftover * 1
print(full_boxes)
print(leftover)
print(f"HK${charge:.2f}")Expected output
4
5
HK$17.00Four complete boxes hold 24 items; five remain. The two packing charges add to 17.
Question 3
item_text = " book "
price_text = "18.75"
quantity_text = "2"
item = item_text.strip().upper()
price = float(price_text)
quantity = int(quantity_text)
print(f"{item}: {quantity} items, HK${price * quantity:.2f}")Expected output
BOOK: 2 items, HK$37.50The displayed receipt is text; the bill is calculated using numeric values.
Question 4
bill = 100
has_student_card = True
if bill >= 100 and has_student_card:
print("Discount")
else:
print("No discount")Expected output
Discount>= includes the boundary; and requires the card as well.
Question 5
scores = [50, 60, 70, 80]
total = 0
passes = 0
for score in scores:
total = total + score
if score >= 60:
passes = passes + 1
print(f"{total / len(scores):.1f}")
print(passes)Expected output
65.0
3The total is 260 over four values. Three scores meet the inclusive passing threshold.
Question 6
def discounted_bill(price, quantity, rate):
return price * quantity * (1 - rate)
print(f"HK${discounted_bill(20, 3, 0.1):.2f}")
print(f"HK${discounted_bill(12.5, 2, 0):.2f}")Expected output
HK$54.00
HK$25.00A 10% discount keeps 90% of the original bill. A zero discount preserves the full amount.
Question 7
balance = 2000
rates = [0.05, -0.10, 0.02]
for rate in rates:
balance = balance * (1 + rate)
print(f"HK${balance:.2f}")
# This scenario omits transaction fees.Expected output
HK$2100.00
HK$1890.00
HK$1927.80Each rate acts on the updated balance. The rates are assumed, and actual costs need separate modelling.
Question 8
scores = [60, 80, 100]
average = sum(scores) / len(scores)
print(average)
# Hand check: (60 + 80 + 100) / 3 = 80.Expected output
80.0The original code computes a total rather than an average. A successful run does not establish correctness.
Question 9
prices = [12.5, 8.0, 9.5]
prices.append(5.0)
prices.remove(8.0)
ordered = prices.copy()
ordered.sort()
print(prices)
print(ordered)
print(f"HK${sum(prices) / len(prices):.2f}")Expected output
[12.5, 9.5, 5.0]
[5.0, 9.5, 12.5]
HK$9.00The three remaining prices total 27. A sorted copy provides ascending order without rearranging the updated original.
Question 10
def days_to_goal(start, daily_saving, goal):
balance = start
days = 0
while balance < goal:
balance = balance + daily_saving
days = days + 1
return days
print(days_to_goal(50, 15, 200))
print(days_to_goal(200, 15, 200))
# Hand check: 50 + 10 * 15 = 200; starting at 200 needs zero deposits.Expected output
10
0The condition controls repetition. Ten deposits reach the goal; when the starting balance already reaches it, the body runs zero times.