Challenge hints & worked solutions
CHALLENGE 011 · BUILD IT
Can I Watch This Film?
A fictional film has a minimum viewing age of 12. Make a short age checker that tells a viewer whether they meet the film’s age rule. The age requirement must be easy to change in the code.
Reveal a hint (from the printed book)
Compare the entered age with 12 using >=. Display one of two messages.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 11 - Can I Watch This Film?
MINIMUM_AGE = 12
age = int(input("How old are you? "))
if age >= MINIMUM_AGE:
print("You can watch this film.")
else:
print("This film is for viewers aged 12 and over.")
Save this Python file ↓CHALLENGE 012 · BUILD IT
Even or Odd Detective
Write a program that classifies an integer as even or odd. Include the number in the result so the user can see which value was checked.
Reveal a hint (from the printed book)
When number % 2 is zero, the number is even. This works for negative integers too.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 12 - Even or Odd Detective
number = int(input("Enter a whole number: "))
if number % 2 == 0:
print(f"{number} is even.")
else:
print(f"{number} is odd.")
Save this Python file ↓CHALLENGE 013 · BUILD IT
Join the Coding Club
A fictional coding club accepts learners aged 12 to 17 inclusive, but only when they have permission to join. Check both rules before giving a decision.
Reveal a hint (from the printed book)
Combine the age-range rule and the permission check using and. Use .strip().lower() to normalise yes/no.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 13 - Join the Coding Club
age = int(input("Enter your age: "))
permission = input("Do you have permission? (yes/no): ").strip().lower()
if 12 <= age <= 17 and permission == "yes":
print("You can join the coding club!")
else:
print("You do not meet the joining rules yet.")
Save this Python file ↓CHALLENGE 014 · BUILD IT
Dress for the Weather
Build a temperature-based clothing suggestion for a fictional weather app. Use these bands: below 10°C = coat; from 10°C up to (but not including) 20°C = jumper; 20°C or warmer = T-shirt.
Reveal a hint (from the printed book)
Try one test for temperatures below 10, then one for temperatures below 20, followed by else.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 14 - Dress for the Weather
temperature = float(input("Temperature in Celsius: "))
if temperature < 10:
print("Wear a coat.")
elif temperature < 20:
print("A jumper is a good idea.")
else:
print("A T-shirt should be fine.")
Save this Python file ↓CHALLENGE 015 · BUILD IT
Discount Day
An online shop gives 10% off orders of £30.00 or more. Write a program that calculates the amount the customer pays after any discount.
Reveal a hint (from the printed book)
Use >= 30 for the threshold. Multiplying by 0.90 leaves 90% of the original price.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 15 - Discount Day
spend = float(input("Order value in pounds: "))
if spend >= 30:
final_price = spend * 0.90
else:
final_price = spend
print(f"Final price: £{final_price:.2f}")
Save this Python file ↓CHALLENGE 016 · BUILD IT
Badge for a Quiz Score
A quiz has 20 marks available. Award a Bronze badge for 0–9, Silver for 10–15, and Gold for 16–20. For now assume the score is a valid integer from 0 to 20.
Reveal a hint (from the printed book)
Check score >= 16 first; otherwise check score >= 10, then use else.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 16 - Badge for a Quiz Score
score = int(input("Quiz score (0-20): "))
if score >= 16:
print("Gold badge")
elif score >= 10:
print("Silver badge")
else:
print("Bronze badge")
Save this Python file ↓CHALLENGE 017 · DEBUG IT
The Boundary-Value Bug
A shop should give 10% off orders of £50.00 or more. Its program works at most prices but fails at precisely £50.00. Find and correct the faulty comparison.
Reveal a hint (from the printed book)
The printed requirement says “£50 or more”, so the comparison must include equality.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 17 - The Boundary-Value Bug
price = float(input("Order value in pounds: "))
if price >= 50:
final = price * 0.90
print("Discount applied")
else:
final = price
print("No discount")
print(f"Final price: £{final:.2f}")
Save this Python file ↓CHALLENGE 018 · IMPROVE IT
Choose a Username
A simple username checker already requires at least six characters. Improve it so blank or whitespace-only names fail, names containing spaces fail, and rejection messages explain the problem.
Reveal a hint (from the printed book)
A name made of spaces becomes empty after .strip(). Use " " in username to detect an embedded space.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 18 - Choose a Username
username = input("Choose a username: ")
if not username.strip():
print("Rejected: the username cannot be blank.")
elif len(username) < 6:
print("Rejected: use at least 6 characters.")
elif " " in username:
print("Rejected: spaces are not allowed.")
else:
print("Username accepted")
Save this Python file ↓CHALLENGE 019 · SOLVE IT
Which Travel Ticket?
A fictional transit operator sells three tickets. Child: ages 0–15, £4. Student: ages 16+ with student status, £6. Standard: ages 16+ without student status, £9. Build a decision program; assume ages are zero or greater.
Reveal a hint (from the printed book)
Check whether the passenger qualifies as a child before testing student status.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 19 - Which Travel Ticket?
age = int(input("Enter your age: "))
student = input("Are you a student? (yes/no): ").strip().lower()
if age <= 15:
print("Child ticket: £4.00")
elif student == "yes":
print("Student ticket: £6.00")
else:
print("Standard ticket: £9.00")
Save this Python file ↓CHALLENGE 020 · DEBUG IT
The Pop-Up Ticket Desk
A fictional ticket desk charges £12 for adults (age 16+) and £7 for children (under 16). Members get 20% off either fare. A starter program gets the child-member total wrong. Repair the order in which it calculates the price.
Reveal a hint (from the printed book)
Set the child or adult base fare first. Only then apply the member percentage reduction.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
# Challenge 20 - The Pop-Up Ticket Desk
age = int(input("Passenger age: "))
member = input("Are you a member? (yes/no): ").strip().lower()
if age < 16:
price = 7.00
else:
price = 12.00
if member == "yes":
price = price * 0.80
print(f"Ticket total: £{price:.2f}")
Save this Python file ↓