Python exercises are most useful at the right difficulty: hard enough to make you think, not so hard that you can't tell what went wrong. This page groups exercises into three levels, with a sample task and solution for each, and explains what makes a task beginner, intermediate or advanced:
| Level | Typical task | Main skill tested |
|---|---|---|
| Beginner | calculate a ticket total, validate one input | single concepts, visible results |
| Intermediate | parse a file, summarise with functions and dictionaries | combining several pieces correctly |
| Advanced | design a tested component with replaceable parts | decisions, trade-offs and evidence |
The examples come from a community cinema's ticketing. For hundreds of short interactive tasks with instant feedback, use the course's Python exercises page, which filters by chapter, type and difficulty.
Beginner exercises
Beginner exercises use a few familiar operations, such as variables, arithmetic, if statements, loops and print(), and produce a result you can check by eye.
Sample task: a cinema charges £8 per adult and £5 per child, with £2 off the whole booking for members. Write ticket_total(adults, children, member), rejecting negative counts.
def ticket_total(adults, children, member=False):
if adults < 0 or children < 0:
raise ValueError("ticket counts cannot be negative")
total = adults * 8 + children * 5
if member and total > 0:
total -= 2
return totalShort code can still hide an important boundary: should the member discount apply to an empty booking and produce −£2? The total > 0 check answers that. More beginner exercises: convert temperatures, count vowels in a word, print a times table, find the largest number in a list without max(), and check whether a year is a leap year.
Intermediate exercises
Intermediate exercises combine functions, collections and data from outside the program, so several parts must cooperate correctly.
Sample task: given a list of screening records like "Fri,Dune,84" (day, film, tickets sold), return total tickets per film and the best-selling day, skipping malformed lines.
def summarise(lines):
per_film, per_day, skipped = {}, {}, 0
for line in lines:
parts = line.split(",")
if len(parts) != 3 or not parts[2].strip().isdigit():
skipped += 1
continue
day, film, sold = parts[0].strip(), parts[1].strip(), int(parts[2])
per_film[film] = per_film.get(film, 0) + sold
per_day[day] = per_day.get(day, 0) + sold
return per_film, max(per_day, key=per_day.get), skippedDifficulty comes from the contracts between pieces: the parser must produce exactly what the counter expects, and bad data must be handled without stopping everything. More intermediate exercises: a word-frequency report from a text file, a JSON settings loader with defaults, and a class that tracks seat bookings with validation.
Advanced exercises
Advanced exercises ask for design, testing and performance decisions, not just longer code. You decide on interfaces, justify trade-offs and provide evidence such as tests or measurements.
Sample task: build a booking service whose seat availability can come from either an in-memory store (for tests) or a database (in production), with tests that never touch the real database.
from typing import Protocol
class SeatStore(Protocol):
def available(self, screening: str) -> int: ...
def reserve(self, screening: str, seats: int) -> None: ...
class MemoryStore:
def __init__(self, seats):
self.seats = dict(seats)
def available(self, screening):
return self.seats.get(screening, 0)
def reserve(self, screening, seats):
self.seats[screening] -= seats
def book(store: SeatStore, screening: str, seats: int) -> bool:
if seats <= 0 or store.available(screening) < seats:
return False
store.reserve(screening, seats)
return TrueThe design lets tests pass a MemoryStore while production passes a database-backed class with the same methods. Advanced doesn't mean obscure: the best advanced solutions are clear, tested and explain their decisions. More advanced exercises: a rate-limited API client with retries, a CSV-to-database importer with transactions, and a profiled optimisation of a slow report.
Feedback routes
Use feedback to decide when to move up a level:
- The course's Python exercises page filters by topic (chapter), type (fill in the blanks, predict the output, multiple choice) and difficulty, and checks answers instantly with hints and explanations.
- The Python quiz mixes questions across chapters, with relaxed, timed and exam modes.
- Your own tests give feedback on longer exercises: write them before the solution.
A reasonable rule: when you solve most exercises at one level without hints, and can explain why each answer is right, attempt the next level. Scoring highly by repeating the same questions until the answers are memorised isn't the same as fluency; vary the questions, revisit topics after a few days, and turn a solved exercise into a slightly different one of your own.
Independent practice and a worked check
Task: use the Python exercises page to attempt selected chapter tasks, then extend one into a tested independent solution.
- Filter to a chapter you finished recently and the "medium" level; complete ten exercises.
- Pick one you found hard and rewrite it as a function with your own test cases:
def leap_year(year):
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
for year, expected in [(2024, True), (1900, False), (2000, True), (2023, False)]:
assert leap_year(year) == expected, year
print("leap year rules pass")The cases include the century exceptions, which is where most leap-year solutions fail. For the worked check, what makes an advanced exercise valuable is design and trade-off decisions with evidence, not simply more lines of code.
Reference and next practice
Use the interactive Python exercises and Python quiz, then continue with quizzes by chapter and the beginner projects.
Python Exercises by Difficulty Summary
- Beginner exercises: Beginner tasks combine a few familiar operations with directly visible results.
- Intermediate exercises: Intermediate tasks combine functions, collections and external data boundaries.
- Advanced exercises: Advanced tasks ask for design, testing and performance decisions rather than merely longer syntax.
- Feedback routes: Existing exercise filters let learners choose topic, type and difficulty.
Python Exercises by Difficulty Examples
Each example shows the code, the output it produces and what each part does.
Python Exercises by Difficulty in a small program
A tiny helper that suggests the next step from a practice score:
def stage_for(score):
if score < 50:
return "review fundamentals"
if score < 80:
return "practise combinations"
return "attempt a design task"
print(stage_for(72))practise combinationsLine-by-line explanation
- Lines 2 to 3Below 50%, revisit the fundamentals for the chapter.
- Lines 4 to 5Between 50% and 79%, practise combining concepts.
- Line 6At 80% or above, try a design task. A score of 72 falls in the middle band.
Beginner and intermediate solutions in action
def ticket_total(adults, children, member=False):
if adults < 0 or children < 0:
raise ValueError("ticket counts cannot be negative")
total = adults * 8 + children * 5
if member and total > 0:
total -= 2
return total
def summarise(lines):
per_film, per_day, skipped = {}, {}, 0
for line in lines:
parts = line.split(",")
if len(parts) != 3 or not parts[2].strip().isdigit():
skipped += 1
continue
day, film, sold = parts[0].strip(), parts[1].strip(), int(parts[2])
per_film[film] = per_film.get(film, 0) + sold
per_day[day] = per_day.get(day, 0) + sold
return per_film, max(per_day, key=per_day.get), skipped
print(ticket_total(2, 3), ticket_total(2, 3, member=True), ticket_total(0, 0, member=True))
records = ["Fri,Dune,84", "Sat,Dune,120", "Sat,Amelie,45", "Sun,Amelie", "Sun,Up,lots"]
print(summarise(records))31 29 0
({'Dune': 204, 'Amelie': 45}, 'Sat', 2)Line-by-line explanation
- Lines 5 to 6The member discount only applies to a non-empty booking.
- Lines 13 to 15Lines with the wrong number of fields or a non-numeric count are skipped and counted, not crashed on.
- Line 19
max(per_day, key=per_day.get)returns the day with the most tickets.
An advanced task with a replaceable store
class MemoryStore:
def __init__(self, seats):
self.seats = dict(seats)
def available(self, screening):
return self.seats.get(screening, 0)
def reserve(self, screening, seats):
self.seats[screening] -= seats
def book(store, screening, seats):
if seats <= 0 or store.available(screening) < seats:
return False
store.reserve(screening, seats)
return True
store = MemoryStore({"Dune 19:30": 5})
results = [book(store, "Dune 19:30", n) for n in (3, 3, 2, 0)]
print(results, store.available("Dune 19:30"))
print(book(store, "Unknown film", 1))[True, False, True, False] 0
FalseLine-by-line explanation
- Lines 9 to 13The booking rule depends only on two store methods, so any store with those methods works.
- Line 16Three seats succeed, the next three fail because only two remain, two succeed, and zero is rejected.
Common Python Exercises by Difficulty Mistakes
Jumping to advanced exercises too early
Week 1: "build a full booking website with a database and payments"Week 1: ticket totals and input validation
Week 3: summarise screening files with functions and dictionaries
Week 6: a tested booking component with a replaceable storeTasks far above your level give frustration without clear feedback about what to learn next.
Treating repeated correct answers as mastery
Retake the same quiz until every answer is memorised -> 100%Mix topics, change the numbers in solved exercises, revisit after a few days,
and explain each answer in one sentence.Python Exercises by Difficulty in Real Projects
Exercises and real skills
Each level mirrors a stage of real work. Beginner exercises train the precise use of syntax that every program depends on. Intermediate exercises reflect most everyday programming: reading data, transforming it with functions and handling bad input. Advanced exercises reflect professional engineering: designing interfaces, testing with substitutes for external systems and justifying decisions to colleagues.
Employers and interviewers look for the intermediate and advanced skills in particular, so once the basics are comfortable, spend most practice time on tasks that combine concepts and require decisions.
Python Exercises by Difficulty FAQ
What are good Python exercises for beginners?
Tasks that use one or two concepts with results you can check by eye: totals and discounts, temperature conversion, counting vowels, times tables, leap years, and finding the largest value in a list without built-ins. The interactive exercises on this site are organised by chapter for this reason.
How do I know when to move to harder Python exercises?
When you solve most exercises at your current level without hints and can explain why each answer works. Then try the next level on a familiar topic before tackling unfamiliar ones.
Do Python exercises come with solutions?
The interactive exercises on this site check your answer instantly and offer hints and explanations. The sample tasks on this page include solutions; attempt each one before reading it.
What is the difference between exercises and projects?
Exercises focus on one or a few concepts with a clear expected answer. Projects combine many concepts, have open-ended requirements and need design decisions. Use exercises to build fluency and projects to practise putting it together.
How long does it take to get good at Python exercises?
With regular practice, most learners handle beginner exercises within a few weeks and intermediate ones within a few months. Consistent daily practice and reviewing mistakes matter more than total hours.
Python Exercises by Difficulty Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
What makes an advanced exercise valuable?
Which review concern is valid for python exercises by difficulty?
Python Exercises by Difficulty Quiz
2 questions to check what you learned.
What makes an advanced exercise valuable?
- Only a larger line count
- Design and tradeoff decisions with evidence
- Python ignores the distinction
Which statement correctly describes advanced exercises?
- Advanced tasks ask for design, testing and performance decisions rather than merely longer syntax.
- Only the example output matters, not the rule
- Every operation has the same behavior