Book-matched resources · Chapter 01 · Challenges 001–010

Your First Python Challenges

Try the printed challenge before revealing a hint or the example solution. Starter files are available only where the book supplies one.

Challenge hints & worked solutions

CHALLENGE 001 · BUILD IT

The Event Ticket

An event organiser needs a personalised ticket. Write a program that asks for an attendee’s name and the event they are attending, then creates a simple ticket on screen.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

Start by collecting both answers with input(). Put descriptive labels before each value in your ticket.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

name = input("Attendee name: ")
event = input("Event name: ")
print("=" * 30)
print("         EVENT TICKET")
print("=" * 30)
print(f"Name: {name}")
print(f"Event: {event}")
print("Enjoy the event!")
Save this Python file ↓
CHALLENGE 002 · IMPROVE IT

Build a Welcome Banner

The supplied program already displays a welcome banner. Improve it while keeping the original greeting.

Reveal a hint (from the printed book)

Choose a fixed banner width, then explore a string method that places text in the middle of that width.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

width = 36
print("=" * width)
print("   WELCOME ABOARD")
title = input("Choose a banner title: ")
print(title.center(width))
print("-" * width)
print("Enjoy your visit!")
Save this Python file ↓
CHALLENGE 003 · BUILD IT

My Three Favourites

Create a one-sentence profile by collecting three favourite things from the user.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

Three input() calls can save the values. A formatted string can bring them together in one sentence.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

music = input("Favourite music: ")
food = input("Favourite food: ")
activity = input("Favourite activity: ")
print(f"My favourites: {music}, {food} and {activity}.")
Save this Python file ↓
CHALLENGE 004 · BUILD IT

Next Birthday Calculator

Make a tiny calculator that tells someone how old they will be on their next birthday.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

input() returns text. Convert the value with int() before adding 1.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

age = int(input("How old are you now? "))
print(f"On your next birthday, you will be {age + 1}.")
Save this Python file ↓
CHALLENGE 005 · BUILD IT

The Snack Stand

A snack stand needs to calculate the cost of buying several identical snacks. Use pounds (£) in this example; the same calculation works with other currencies.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

Convert the unit price with float() and quantity with int(). Format the result to two decimal places.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

price = float(input("Price of one snack: £"))
quantity = int(input("How many snacks? "))
total = price * quantity
print(f"Total: £{total:.2f}")
Save this Python file ↓
CHALLENGE 006 · SOLVE IT

Seconds Into Minutes

Design a program that converts a non-negative number of seconds into minutes and seconds. Do not use a built-in time-formatting function.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

One operation finds complete groups of 60; another finds what is left over. Try // and %.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

seconds = int(input("Total seconds: "))
minutes = seconds // 60
remaining = seconds % 60
print(f"{minutes}:{remaining:02d}")
Save this Python file ↓
CHALLENGE 007 · BUILD IT

Hot or Cold?

A weather app needs a quick temperature converter. Convert degrees Celsius into degrees Fahrenheit using the formula below.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

Use the printed formula exactly, then format the Fahrenheit result with one decimal place.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

celsius = float(input("Temperature in Celsius: "))
fahrenheit = celsius * 9 / 5 + 32
print(f"{celsius:.1f}°C = {fahrenheit:.1f}°F")
Save this Python file ↓
CHALLENGE 008 · DEBUG IT

Why Is the Total Wrong?

A checkout program adds two prices, but entering 4 and 6 prints 46 rather than the expected total. Find the bug, fix it and test decimal prices.

Reveal a hint (from the printed book)

The plus sign behaves differently with strings and numbers. Convert the inputs before calculating.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

price_1 = float(input("First price: "))
price_2 = float(input("Second price: "))
total = price_1 + price_2
print(f"Total: £{total:.2f}")
Save this Python file ↓
CHALLENGE 009 · DEBUG IT

Design a Rectangle

A rectangle calculator finds the correct area but uses the same calculation for perimeter. Repair the faulty line without damaging the area calculation.

Reveal a hint (from the printed book)

The perimeter goes around the whole boundary, so it uses two widths and two heights.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

width = float(input("Width: "))
height = float(input("Height: "))
area = width * height
perimeter = 2 * (width + height)
print(f"Area: {area:g}")
print(f"Perimeter: {perimeter:g}")
Save this Python file ↓
CHALLENGE 010 · BUILD IT

The Three-Score Average

A student wants to find the arithmetic mean of three scores. Create a program that works even when a score includes decimal places.

Start from a blank Python file; no starter supplied for this challenge.Download worked solution .py ↓
Reveal a hint (from the printed book)

Add all three values first, then divide by 3. Brackets make the intended order unmistakable.

Reveal a worked Python solution

One possible implementation. Check the book's tests and try an extension after comparing.

first = float(input("Score 1: "))
second = float(input("Score 2: "))
third = float(input("Score 3: "))
average = (first + second + third) / 3
print(f"Average score: {average:.2f}")
Save this Python file ↓