Explore structured python programming courses, solved problems, simulations and Python activities.
Real tools are made of the small ideas that you already know, put together with care. In this course you plan and build three tools: a contact book that uses a dictionary and try and except, a code cracker that counts letters and uses the shift of a Caesar code, and a marks report that uses the statistics module, sorting and binary search. Each project starts with a plan and a table of expected answers, keeps the thinking in small functions, and ends with ideas for you to extend. A lesson on a command menu joins tools into one program that reads commands, and a last lesson gives a method for planning your own project and shows what comes next. The practice tests your functions on many cases and tells you which ones fail.
Real text is messy: capital letters, extra spaces, punctuation, lines that arrive in a strange form. Most programs spend much of their time reading, cleaning and cutting text. In this course you cut text with split, glue it with join, clean it with strip, lower and replace, count the words with a dictionary, write and break a secret code, and check palindromes and anagrams. A lesson on looking inside text shows how to find a piece, test the kind of characters, and read a line such as name equals value. A text toolkit with a table of tests is the project at the end. The practice runs your functions on messy inputs and tells you which ones fail.
Recursion is a function that calls itself on a smaller problem. It sounds strange at first, but it is how we naturally think about problems that contain smaller copies of themselves: a folder inside a folder, a word whose last part is a shorter word, a tower of discs that holds a smaller tower. In this course you find the base case that stops the calls, write countdowns, sums, factorials, powers and Fibonacci numbers, follow the call stack going down and coming back up, and see why the simple Fibonacci function is slow. You use recursion on text and lists, and you finish with a project that walks through folders inside folders. The practice runs your functions on many inputs and tells you which ones fail.
Finding things and putting them in order are the two most common jobs in computing. A phone finds a contact among thousands, and a website lists the cheapest items first. In this course you search a list item by item and then by halving it, you see why the second way is so much faster, and you sort lists with Python's tools and with small sorting methods that you write yourself. A lesson on counting the work shows how to compare methods by the number of steps they need, and why the answer matters when the list grows. A class ranking with ties is the project at the end. The practice runs your code on many lists and tells you which results are wrong.
A module is a toolbox of code that you can use in your own program. Someone has already written, tested and improved a function for the square root, for rolling a die, for the median of a list and for the number of days between two dates. In this course you import the math, random, statistics and datetime modules, use their tools to solve small everyday problems, and learn the ways of importing. A lesson on finding and choosing tools shows how to look inside a module with dir and help, how to read an import error, and which mistakes make an import fail. A dice laboratory is the project at the end: you roll a die hundreds of times and see how fair it is. The practice runs your code and tells you which results are wrong.
Every program meets bad input and surprises: a word where a number is needed, a zero to divide by, a key that is missing. A program that crashes is a poor program, and a program that hides its errors is a worse one. In this course you learn to read an error message and name the common errors, catch them with try and except so that the program goes on, use else and finally, and build a loop that asks until the user gives a good answer. You learn to raise your own errors with a clear message, and to choose between checking first and catching afterwards. A safe data reader is the project at the end. The practice runs your code on good and bad input and tells you which cases fail.
You know lists and dictionaries. Here are two more containers. A tuple is a row that cannot change, which is just right for values that belong together, such as the two numbers of a point. A set keeps every value only once, answers a yes or no question very fast, and can compare two groups: who is in both clubs, who is in only one. You build both, unpack tuples, return two values from a function, remove repeats, and use the set operations to solve small puzzles. A lesson on choosing between list, tuple, set and dictionary pulls the four together, and a school clubs project uses them all. The practice runs your code on real data and tells you which results are wrong.
A list finds items by position. A dictionary finds them by a name. If you want the phone number of Ravi, you would like to ask for Ravi, and not for position 7. In this course you make dictionaries of keys and values, add, change and remove pairs, look things up without errors, go through a dictionary with a loop, and count with it. You learn to put a dictionary inside a dictionary, to keep a list as a value, and to group items. A tiny shop with prices, stock and a basket is the project at the end. The practice runs your code on real data and tells you which results are wrong.
These are part of our upcoming paid plans.
A monk moves a tower of discs, one at a time, and the legend says the world ends when he is done. How many moves is that? Why is the simple Fibonacci function so slow, and how does a dictionary fix it? In this workshop you learn a way to think recursively with four questions, solve puzzles on lists, numbers and towers, keep a memory of answers, learn the limits of recursion and when to use a loop, and meet puzzles where every step has a choice, such as all the subsets of a set and all the arrangements of letters. A puzzle book of tested functions is the project at the end, and a timed test follows. The practice runs your functions on many inputs and tells you which ones fail.