Try the Python courses

7 Python courses and 113 exercises, open to try free in your browser — no sign-up, nothing to install and nothing saved. Each exercise has a problem, starter code, hints and tests that check your code instantly, and links to the lesson that teaches what it needs.

Python Fundamentals

A first Python course, supported by 19 core concept lessons. Start with output, input and variables, then use decisions, loops and functions in progressively broader programs.

  1. Hello, World!
  2. Welcome Aboard
  3. Hello, Human
  4. Name and Age
  5. Age in the Future
  6. Who Goes There?
  7. Grade Calculator
  8. Name Shout
  9. Repeated Greetings
  10. Check the Age
  11. Seven Guesses
  12. Guess with a Score
  13. Times Table
  14. Merry Christmas
  15. Christmas Tree
  16. Function Basics
  17. Adding and Subtracting
  18. The Login Gate
  19. Introduction to Lists in Python
  20. Multiples Machine
  21. Bug Clinic
  22. Closest Guess
  23. Factor Finder
  24. Prime Detector
  25. Pair Every Name with Every Game
  26. The Prime Collector
  27. All Passed
  28. Score a Memory Game
  29. Introduction to Dictionaries in Python
  30. Account Lookup
  31. Find and Replace
  32. Program Menu
  33. Weather Readings
  34. Process Login Attempts
  35. Dice Battle
  36. Palindrome Discovery
  37. Card Game Champion

Python Skills for Lineup 4

Build the Python skills for a Lineup 4 agent: read positions and board dictionaries, find legal moves, check whether the centre is free, use lists to express preferences, build every winning line, then search those lines for a move that wins immediately.

  1. The Position Code
  2. Reading the Board
  3. Where Does the Piece Land?
  4. Every Legal Move
  5. Is the Centre Free?
  6. Play as central as I can
  7. Find all winning sets?
  8. Find a Winning Move

Python Basics with Turtle

Learn the first ideas of Python by drawing with a turtle: printing, variables, arithmetic, input, for loops, decisions and functions. Every program draws something, and the tests check the drawing. Press Run to watch the turtle draw; drawing needs Python running in your browser.

  1. Hello, Turtle
  2. Turtle Says Hello
  3. Rectangle Variables
  4. Rectangle Perimeter
  5. Triangle on Request
  6. Loop Any Polygon
  7. Square Spiral
  8. Square or Triangle?
  9. Polygon by Name
  10. A Polygon Function
  11. Polygon Perimeter
  12. Shape Picker

API basics

Talk to real web APIs with Python's requests library. Learn to fetch a response, inspect its values and structure, find the fields you need, and turn them into a useful report. Practise query parameters and pagination, failed requests, missing data, request and response headers, POSTing JSON, and bounded retries after 429 Too Many Requests. By the midpoint, use a supplied inspector to explore a large response as keys and Python types. Finish with an unfamiliar Pokémon species response and a report that handles failed requests. No accounts or API keys are needed.

  1. Your First GET Request
  2. Query Parameters
  3. Follow the Next Page
  4. Status Codes
  5. When Requests Fail
  6. Book Report
  7. Map a Response
  8. Reading Response Headers
  9. Sending Headers
  10. POST Some JSON
  11. Capital Quiz
  12. Pokemon Leaderboard
  13. Too Many Requests
  14. Retry Politely
  15. Species Field Report

Python Object-Oriented Programming (OOP) with Dataclasses

Object-Oriented Programming in Python, taught through short coding exercises. Build Python classes and independent objects, put behaviour in methods, and use a Python dataclass to remove repetitive setup code. Practise OOP concepts with examples of field defaults, equality, separate mutable lists, composition, validation, frozen values, inheritance and polymorphism. Finish by validating and exporting a small gradebook.

  1. Python Classes: Create Independent Objects
  2. Python Objects: Update a Parcel Collection
  3. Python Methods and self: Change Object State
  4. OOP Example: Fill a Tank Without Overflow
  5. Your First Python Dataclass
  6. Dataclass Methods: Calculate Route Times
  7. Python Dataclass Defaults and Equality
  8. Dataclass Challenge: Find the Basketball Leaders
  9. Python Dataclass default_factory: Separate Lists
  10. Dataclass List Methods: Avoid Duplicate Members
  11. OOP Composition: Add Up Objects in a Dataclass List
  12. OOP Composition Example: A Building of Floors and Rooms
  13. Dataclass Validation with __post_init__
  14. Dataclass Validation Example: Reservation Limits
  15. Frozen Dataclasses: Make an Updated Copy
  16. Frozen Dataclass Example: Award Score Bonuses
  17. Python OOP Inheritance and Method Overriding
  18. OOP Polymorphism Example: Total Mixed Tickets
  19. Python Dataclass asdict: Export Nested Records
  20. OOP Dataclass Project: Build a Batch Grader

Python Context Managers: the with Statement and @contextmanager

Learn Python context managers: what the with statement does, and how to write your own context manager with @contextmanager from contextlib. Start with a context manager that runs code before and after a with block, then use try/finally so the clean-up runs even when the block raises an error. Change a game setting and restore it, yield an open file to with ... as, and put multiple context managers in one with statement to work with several files at once. Finish by writing the same context managers as classes with __enter__ and __exit__.

  1. Write Your First Context Manager with @contextmanager
  2. Nested with Statements: Two Context Managers
  3. try/finally: Cleanup That Runs Even After an Error
  4. Temporary Settings: Change a Value and Restore It
  5. with ... as: Yield a File from a Context Manager
  6. Multiple Context Managers in One with Statement
  7. Merge Score Files into a Leaderboard
  8. __enter__ and __exit__: a Context Manager Class
  9. Context Manager Class with __init__ and a Return Value
  10. Temporary Settings as a Context Manager Class

Python Generators

Learn generators: generator expressions, yield, infinite generators and close(), then for loops, lazy evaluation, filters, pipelines, reading a file line by line and memory, ending with a lazy log-file parser. Assumes basic functions, arithmetic, lists, loops and reading text files.

  1. Your First Generator: next()
  2. Write a Generator with yield
  3. Infinite Running Totals
  4. Infinite Fibonacci and close()
  5. Loop Over a Generator with for
  6. yield vs return: Lazy Evaluation
  7. Filter Lines with a Generator
  8. Generator Pipeline: Take the First N
  9. Read a File Line by Line
  10. Generator Expression vs List: Memory
  11. Parse a Log File with Generators

Want to keep your progress? Sign up free to save every exercise you pass and get AI hints. Reading first? Browse the Python lessons. Teaching a class? See Agent Games for teachers.