Chapter 0 · Section 6 practice
Put the Pieces 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.
1. Represent a percentage
Warm-up. Store 5% as a numeric rate. Print the rate and 5% of HK$200.
Write your answer, then run it.
2. One year of growth
Warm-up. Starting at HK$1000, calculate the balance after one year at an assumed 5% growth. Print two decimals.
Write your answer, then run it.
3. A negative year
Warm-up. Start at HK$1000 and apply a 10% decrease. Print the updated balance with two decimals.
Write your answer, then run it.
4. Use a power
Build your skills. Calculate HK$1000 growing at an assumed 10% per year for 3 years using **. Print two decimals.
Write your answer, then run it.
5. Trace the three years
Build your skills. Use a loop to calculate the same growth as the previous question. Print the year and updated balance each time.
Write your answer, then run it.
6. Compare scenarios
Build your skills. For HK$1000 over 2 years, loop over assumed rates -0.10, 0, and 0.10. Print each rate as a percentage and the final amount.
Write your answer, then run it.
7. Changing annual rates
Build your skills. Start at HK$1000. Apply annual rates 10%, -10%, and 5% in that order. Print the balance after each year.
Write your answer, then run it.
8. Add a deposit at year-end
Challenge. Start at HK$1000. In each of 2 years, first grow the balance by 5%, then add a HK$200 deposit at year-end. Print both year-end balances.
Write your answer, then run it.
9. Growth followed by an annual fee
Challenge. Start at HK$1000. Each year for 2 years: grow by 5%, then subtract a fixed HK$10 fee. Define a function for one year and call it inside the loop. Print each balance.
Write your answer, then run it.
10. Check a savings goal under assumptions
Challenge. Start at HK$1000, apply rates [0.10, -0.10, 0.05], then print the final balance and Goal met if it is at least HK$1050, otherwise Below goal. Add a Python comment explaining why this is not a forecast.
Write your answer, then run it.
Reference answers are locked until all 10 attempts are submitted.
1. Represent a percentage
rate = 0.05
print(rate)
print(200 * rate)Expected output
0.05
10.0Five percent is 5 divided by 100, or 0.05.
2. One year of growth
balance = 1000
rate = 0.05
balance = balance * (1 + rate)
print(f"HK${balance:.2f}")Expected output
HK$1050.00The multiplier includes the original balance and the increase.
3. A negative year
balance = 1000
rate = -0.10
balance = balance * (1 + rate)
print(f"HK${balance:.2f}")Expected output
HK$900.00A rate of -0.10 gives a multiplier of 0.90.
4. Use a power
principal = 1000
rate = 0.10
years = 3
value = principal * (1 + rate) ** years
print(f"HK${value:.2f}")Expected output
HK$1331.00Each year multiplies by 1.10. Three years use the third power; format the display with two decimal places.
5. Trace the three years
balance = 1000
rate = 0.10
years = 3
for year in range(1, years + 1):
balance = balance * (1 + rate)
print(f"Year {year}: HK${balance:.2f}")Expected output
Year 1: HK$1100.00
Year 2: HK$1210.00
Year 3: HK$1331.00The new balance is the starting point for the next year. The loop and formula give the same displayed final result.
6. Compare scenarios
principal = 1000
years = 2
rates = [-0.10, 0.00, 0.10]
for rate in rates:
value = principal * (1 + rate) ** years
print(f"{rate:.0%}: HK${value:.2f}")Expected output
-10%: HK$810.00
0%: HK$1000.00
10%: HK$1210.00These are separate assumptions, not probabilities. Reset the calculation from the principal for each rate.
7. Changing annual rates
balance = 1000
annual_rates = [0.10, -0.10, 0.05]
for rate in annual_rates:
balance = balance * (1 + rate)
print(f"HK${balance:.2f}")Expected output
HK$1100.00
HK$990.00
HK$1039.50A 10% rise followed by a 10% fall does not cancel; each percentage uses a different starting balance.
8. Add a deposit at year-end
balance = 1000
rate = 0.05
yearly_deposit = 200
for year in range(1, 3):
balance = balance * (1 + rate)
balance = balance + yearly_deposit
print(f"Year {year}: HK${balance:.2f}")Expected output
Year 1: HK$1250.00
Year 2: HK$1512.50Deposit timing matters. A year-end deposit does not earn that same year's growth in this model.
9. Growth followed by an annual fee
def one_year(balance, rate, fee):
return balance * (1 + rate) - fee
balance = 1000
rate = 0.05
fee = 10
for year in range(1, 3):
balance = one_year(balance, rate, fee)
print(f"Year {year}: HK${balance:.2f}")Expected output
Year 1: HK$1040.00
Year 2: HK$1082.00The fixed fee reduces this year's balance and therefore the starting amount for next year.
10. Check a savings goal under assumptions
principal = 1000
annual_rates = [0.10, -0.10, 0.05]
goal = 1050
balance = principal
for rate in annual_rates:
balance = balance * (1 + rate)
print(f"HK${balance:.2f}")
if balance >= goal:
print("Goal met")
else:
print("Below goal")
# The rates are assumed; the code does not establish future returns.Expected output
HK$1039.50
Below goalThe arithmetic checks a stated path. Real outcomes can use other rates and incur additional costs.