Chapter 0 · Section 1 practice
Values, Variables, and Calculations
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.
1. Show a greeting
Warm-up. Print the message Hello, Python! Use matching quotes.
Write your answer, then run it.
2. Text or a calculation?
Warm-up. Print the text 4 + 6, then print the result of adding 4 and 6. Use two lines.
Write your answer, then run it.
3. Money left
Warm-up. You have HK$80 and spend HK$18. Create money_left and print it.
Write your answer, then run it.
4. Update a score
Build your skills. Start with 12 points. Add 8, then subtract 3, reassigning points each time. Print the final value.
Write your answer, then run it.
5. Inspect numeric types
Build your skills. Print the type of quantity, the type of price, and the result of quantity * price.
Write your answer, then run it.
6. Divide in three ways
Build your skills. Print 17 / 5, 17 // 5, and 17 % 5, each on its own line.
Write your answer, then run it.
7. Use parentheses
Build your skills. Write two calculations: add 3 and 5, then multiply the result by 2; multiply 5 by 2, then add 3. Print both.
Write your answer, then run it.
8. Square and cube
Challenge. The side of a square is 6 cm. Print its area using a power. A cube has side 3 cm; print its volume using a power.
Write your answer, then run it.
9. Pack a delivery
Challenge. There are 38 pencils and each box holds 6. Print full boxes, pencils left, and the number accounted for. Use // and %.
Write your answer, then run it.
10. A small shopping budget
Challenge. You have HK$100. Buy 2 notebooks at HK$15 each and 3 pens at HK$4 each. Calculate total_spent and money_left, then print both. Define the inputs yourself.
Write your answer, then run it.
Reference answers are locked until all 10 attempts are submitted.
1. Show a greeting
print("Hello, Python!")Expected output
Hello, Python!Quotes create text; print displays it without the quotes.
2. Text or a calculation?
print("4 + 6")
print(4 + 6)Expected output
4 + 6
10The quoted expression is text; the unquoted expression is evaluated.
3. Money left
money = 80
snack_cost = 18
money_left = money - snack_cost
print(money_left)Expected output
62Subtract spending from the starting amount.
4. Update a score
points = 12
points = points + 8
points = points - 3
print(points)Expected output
17Each update reads the previous value and assigns the new one.
5. Inspect numeric types
quantity = 3
price = 2.5
print(type(quantity))
print(type(price))
print(quantity * price)Expected output
<class 'int'>
<class 'float'>
7.5An integer count times this float price produces a float.
6. Divide in three ways
print(17 / 5)
print(17 // 5)
print(17 % 5)Expected output
3.4
3
2Division gives 3.4; three complete groups of five use 15 items, leaving two.
7. Use parentheses
print((3 + 5) * 2)
print(3 + 5 * 2)Expected output
16
13Parentheses change which operation happens first.
8. Square and cube
square_side = 6
cube_side = 3
print(square_side ** 2)
print(cube_side ** 3)Expected output
36
27A square uses the second power; a cube uses the third power. Units are cm² and cm³.
9. Pack a delivery
pencils = 38
capacity = 6
full_boxes = pencils // capacity
leftover = pencils % capacity
print(full_boxes)
print(leftover)
print(full_boxes * capacity + leftover)Expected output
6
2
38Six full boxes hold 36 pencils; two remain. Reconstructing the total checks the arithmetic.
10. A small shopping budget
budget = 100
notebook_quantity = 2
notebook_price = 15
pen_quantity = 3
pen_price = 4
total_spent = notebook_quantity * notebook_price + pen_quantity * pen_price
money_left = budget - total_spent
print(total_spent)
print(money_left)Expected output
42
58The two product costs are 30 and 12. Add them before subtracting from the budget.