Python first exercises
You reinforce each basic topic with short, real problems and solve an unguided task on your own at the end of every section.
Level 101 · 16 lessons · 15 practice labs
Lessons
Numbers and text
- Exercise: a unit converter
- Exercise: odd, even and simple statistics
- Exercise: cleaning up messy text
- Exercise: encrypt and decrypt with a Caesar shift
- Short task: a username generator that follows the rules
Loops and conditions
- Exercise: a number guessing game
- Exercise: FizzBuzz and its variants
- Exercise: a command-line program with a menu
- Exercise: lock the account after three failed logins
- Short task: generate a weekly on-call rota
Collections and functions
- Exercise: a grade book and averages
- Exercise: remove duplicates from an e-mail list
- Exercise: a phone book with a dictionary
- Exercise: move repeated code into functions
- Short task: a shopping cart with discounts
Capstone
- Capstone: a quiz program that reads its questions from a file
Practice labs
- Centring a title in a star frame: Write a function that places a title in the middle of a star frame of the requested width and returns the list of lines.
- Listing leap years: Write a function that lists the leap years between two years by the calendar rules and handles special cases like 1900 and 2000.
- Validating a check digit: Write a function that validates the check digit of card-like numbers with the Luhn algorithm and pass tests with randomly generated valid and invalid numbers.
- Giving change with the fewest coins: Write a function that gives change with the fewest coins from a limited coin stock and reports when it is impossible.
- Building an acronym from an organisation name: Write a function that builds upper-case acronyms from organisation names, skipping joining words such as 've' and 'ile'.
- Compressing repeated letters: Write two functions that compress 'aaabcc' into 'a3b1c2' and expand it back, so the expanded text always equals the original.
- Wrapping text to a line width: Write your own loop that splits text into lines of at most N characters without breaking any word.
- Normalising book numbers: Write a function that cleans 10- and 13-digit book numbers containing dashes and spaces, validates the check digit and reports invalid ones with a reason.
- Calculating a parking fee: Write a function for a car park tariff with a flat first hour and an extra charge for every half hour started after that.
- Tracing an elevator step by step: Write a loop that works out which floors an elevator passes and how many floors it travels in total for a list of calls.
- Allocating adjacent cinema seats: Write a function that finds the requested number of adjacent free seats in an occupancy grid starting from the front row, returning None when there is no room.
- Reading a matrix in spiral order: Write a function that walks a rectangular matrix given as nested lists in spiral order and handles edge cases like a single row or column.
- Finding absentees from a register: Write a function that returns, from a class list and an attendance list, who is absent and who attended without being on the list.
- Listing products that need restocking: Write functions that return the products in a stock dictionary that fell below their threshold, together with a suggested order quantity.
- Building a league table from results: Write functions that compute wins, draws, goal difference and points from match scores and sort the table by league rules.
About this course
You reinforce each basic topic with short, real problems and solve an unguided task on your own at the end of every section.
What you will learn
- Numbers and text
- Loops and conditions
- Collections and functions
- Capstone
Prerequisites
No prior knowledge is needed; the course starts from zero.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at beginner level; every term is explained where it first appears.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.