Python Bakery

Featured course

Dr. Austin Cory Bart · Dodona

>>>

From your first print statement to recursion.

Introductory programming in Python · no experience needed

An introductory programming course for people writing their first program. Each lesson pairs a short video and reading with a self-check quiz and auto-graded exercises, so you write and run Python from the very first lesson.

What you'll learn

  • The basics: values and types, variables, math, logic, strings and error messages
  • Functions: calling, defining, testing, scope and documentation
  • Conditionals: if statements, nesting and logical patterns
  • Data structures: dataclasses, lists and mutability
  • Loops: for loops and the loop patterns, while loops, and composing them
  • Sequences and files: indexing, iterating over strings, reading data from files
  • Nested data: lists of dataclasses, nested lists, deeply nested structures
  • Efficiency: time complexity, searching and sorting
  • Advanced topics: plotting with matplotlib, recursion and binary trees
  • Three projects: a three-card poker game, an encryption and hashing tool, and a data analysis project

University of Delaware Course material by Cory Austin Bart

Learning path

What's next in this course
Introduction

Computer science

This lesson opens the course by introducing computer science as problem solving, and programming as writing instructions a computer can run. Students learn to define these terms and recognize what programs can and cannot do.

This lesson introduces programming languages and explains why this course uses Python, comparing it briefly to alternatives such as Java and JavaScript. Students learn synonyms for running a program, and write and run their first short Python program in the sandbox.

Status Status Type Title
Programming
Programming: quiz
First Program

This lesson covers the three phases of program execution: input, processing, and output. Students learn to write basic Python code using print to produce output and input to read a value from the user, and combine the two in one program.

Status Status Type Title
Console I/O
Console I/O: quiz
Basic Output
Now You Print
Print Input

Values and types

This lesson introduces values as the computer’s representation of real-world information, covering how to write and print literal values in Python. Students learn to identify the five basic types: integer, float, string, boolean, and None.

Status Status Type Title
Values
Values: quiz
Print Literals
Types
Types: quiz

This lesson covers the seven numeric operators in Python: addition, subtraction, multiplication, division, integer division, exponentiation, and modulo. Students learn to evaluate math expressions, apply operator precedence, and predict whether a result is an integer or a float.

Status Status Type Title
Math
Math: quiz
Print Ops
Complex Formula

This lesson introduces comparison operators such as equal to, not equal to, less than, and greater than, and boolean operators such as and, or and not. Students learn to write and evaluate logical expressions, including expressions that nest several operators together.

Status Status Type Title
Logic
Logic: quiz
Print Logic

Interactive evaluation

This lesson explains what an expression is: a combination of literal values, math, comparison, and boolean operators, and how Python evaluates one step by step. Students learn how print and the console let them run and observe expressions interactively.

Status Status Type Title
Interactive Evaluation
Interactive Evaluation: quiz
Quick Calc

This lesson introduces variables as named storage for data, covering how to define, update, and read them with assignment statements. Students learn the rules for valid variable names and how to judge whether a name is clear and appropriate.

Status Status Type Title
Variables
Variables: quiz
Print Variables

This lesson covers how variable values change over the course of a program, and the difference between an assignment statement and an equality comparison. Students learn to trace variable values step by step, fix ordering bugs, and simplify code by extracting repeated expressions or removing redundant lines.

Status Status Type Title
Tracing
Tracing: quiz
Update Order
Extract Out
Multiple Variables
Redundant Init

This lesson looks at how Python programs execute one statement at a time, and the difference between a statement and an expression. Students practice with puzzle activities that ask them to reorder lines of code so that a program produces the correct result.

Status Status Type Title
Modules
Modules: quiz
Arrange Lines
Arrange Many Lines

This lesson introduces comments as text that Python ignores but that helps human readers understand code, written with the hash symbol. Students learn when comments are useful, including temporarily disabling a line of code by commenting it out.

Status Status Type Title
Comments
Comments: quiz
Comment Out

This lesson introduces modules, packages, and libraries, and the import statement that loads variables from one module into another. Students learn to write and interpret import statements, including importing a specific variable such as pi from the math module.

Status Status Type Title
Importing
Importing: quiz
Import Variable
Provide Variable
Slice Of Pi

This lesson introduces strings as text data made of characters, written with single, double, or triple quotes, and escape characters such as newline. Students learn when to use each quoting style and how to tell a numeric-looking string apart from an actual number.

Status Status Type Title
Strings
Strings: quiz
Single Quotes
Double Quotes
Escape Double
Triple Quotes
Ints Strs
String Of Stuff

String operations

This lesson covers the operators that work on strings: addition, comparison, the membership operator in, and subscripting. Students learn to distinguish indexing a single character from slicing a range, and to use positive and negative indices correctly.

Status Status Type Title
String Operations
String Operations: quiz
String Tests
Print Subscripts
Order Out Of

This lesson introduces Python error messages and tracebacks, covering common error types such as SyntaxError, NameError, and TypeError. Students learn to read an error message to locate and fix a bug, practiced on one example of each error type.

Status Status Type Title
Errors
Errors: quiz
Syntax
Name
Type
Functions

Calling functions

This lesson introduces functions as reusable chunks of code, and how to call them using parentheses and arguments. Students learn the vocabulary around calling functions, including arguments and return values, and see built-in functions such as input, int, round and print in action.

Status Status Type Title
Functions: overview
Functions: overview quiz
Calling Functions
Calling Functions: quiz
Rounding Up
Calls And Variables
Composed Calls
Calls Gone Wrong

Built-in functions

This lesson covers how to read documentation for a built-in function, identifying its parameters, arguments and return value. Students practice nesting function calls, chaining method calls, and combining functions, methods and operators within a single expression.

Status Status Type Title
Built-in Functions
Built-in Functions: quiz
Dashing Name
Highs Lows
Fixing Titles
Parameters Arguments
Mystery Name

Defining functions

This lesson explains how to define a function with the def keyword, giving it a header with named, typed parameters and an indented body ending in a return statement. Students learn to use pass for an empty body, and trace how arguments are assigned to parameters.

Status Status Type Title
Defining Functions
Defining Functions: quiz
Fix Call
Adder
Function Checklist

Testing functions

This lesson introduces unit testing with the assert_equal function, covering how to choose representative test cases and judge whether a set of tests is thorough. It also covers debugging strategies such as the scientific method, print based wolf fence debugging and rubber duck debugging.

Status Status Type Title
Testing Functions
Testing Functions: quiz
Mysterious Math
Mysterious Strings
Be Polite
Grading Curve
Vowel Function
Igplay Atinlay
Debugging Functions
Debugging Functions: quiz

Scopes and bodies

This lesson distinguishes a function’s body, the indented block that runs, from its scope, the region where a variable exists. Students learn the difference between global and local variables, why functions return values rather than variables, and why global variables are discouraged except as constants.

Status Status Type Title
Scopes and Bodies
Scopes and Bodies: quiz
Outside Perimeter
Weekend Off
Calling Inside

This lesson covers documenting code with comments, using the hash symbol for single-line comments and triple-quoted strings for multi-line comments and docstrings. Students learn to write a function’s docstring as the first line of its body, describing its purpose, parameters and return value.

Status Status Type Title
Docstrings
Docstrings: quiz
Bad Lines
Bad Prints
Bad Body
New Docs

Function flow

This lesson traces how values move through a program as functions call each other, with substitution showing how a call is replaced by its returned value. Students learn to read stack frames representing each call’s local variables, and follow data as it passes between functions.

Status Status Type Title
Function Flow
Function Flow: quiz
Timely Extraction
Volume Extraction
String Extraction

External functions

This lesson covers importing functions from other modules, such as randint from random or floor and pi from math, and briefly introduces third-party libraries distributed through the Python Package Index. Students also read code using the Drafter web-app library, whose imported functions build a page from styled text and content components.

Status Status Type Title
External Functions
External Functions: quiz
String Of Letters
Suitable Suit
If statements

If statements

This lesson introduces if statements: a conditional that decides whether a body of code runs, with an optional else body for when it does not. Students learn to trace which lines execute, and apply truthiness, letting values such as the empty string, 0 and None act as false.

Status Status Type Title
If statements: overview
If statements: overview quiz
If Statements
If Statements: quiz
Rainy Days
Driven To Drink
Truthiness
Truthiness: quiz

This lesson covers how to judge a set of unit tests: representative and special cases of input, code coverage as the share of lines the tests execute, and the difference between valid and thorough tests. Students then write unit tests for functions whose implementation they cannot see, and each submission runs against the author’s genuine implementations and several impostors, so the tests must pass on every genuine version and catch every impostor.

Status Status Type Title
Coverage
Coverage: quiz
Code coverage: instructions
Sum Digits
Numeric Day
Split Pay

Nested if statements

This lesson covers nesting if statements inside functions and other if statements, and the indentation rules that determine which body a line belongs to. Students learn to use elif to chain conditions, distinguish it from separate if statements, and remove redundant if statements and redundant comparisons to True.

Status Status Type Title
Nested If Statements
Nested If Statements: quiz
Drinking Function
Possibly Undefined
Animal Rater
Stay Positive
Redundant If

Logical patterns

This lesson presents patterns for structuring conditional logic, including define-and-refine, replacing nested if statements with and, guarding against errors early, and choosing between multiple return statements or one result built up before a single return. It closes with event handling in the Drafter web-app library, where a button names the route function that runs when it is clicked.

Status Status Type Title
Logical Patterns
Logical Patterns: quiz
Check Capacity
Better Pig Latin
Unknown Course
Dispatch the Math
Events
Events: quiz
Structures

This lesson introduces dataclasses, created with the dataclass decorator and the class keyword to bundle several fields into a single new type. Students learn to define a dataclass’s fields with their types, create instances by calling it like a function, and access field values using a period.

Status Status Type Title
Structures: overview
Structures: overview quiz
Dataclasses
Dataclasses: quiz
Finish Movie
Sing a Song
Define Date
Define Address

Using dataclasses

This lesson covers working with dataclass instances: which operations are valid on them, comparing them with the equality operator, and writing functions that consume a dataclass and access its fields. Students learn why a parameter’s type matters, and to tell a dataclass type apart from its instances.

Status Status Type Title
Using Dataclasses
Using Dataclasses: quiz
Count Grocery List Items
Address as String
Dark Pixels

Returning dataclasses

This lesson covers functions that return a dataclass instance, either by mutably updating the instance they receive or by returning a new copy, and how each looks on the stack and heap. Students write functions that return and convert dataclasses, including one type into another, and close with complex state in the Drafter web-app library, where a dataclass holds an application’s state.

Status Status Type Title
Returning Dataclasses
Returning Dataclasses: quiz
Convert Pixels
Make some Cakes
Next Door
Point Turtle
Merge Recipes
Adopt Pet
Complex State
Complex State: quiz

This lesson introduces the list type, created with square brackets and holding multiple values of the same element type. Students learn to write empty and non-empty list literals, apply truthiness rules to lists, predict how a list prints, and write list type annotations such as list[int].

Status Status Type Title
Lists
Lists: quiz
Calorie List
Book List
Emptiness
Listification
The Choice

List operations

This lesson covers operations on lists: indexing and subscripting to access elements, the in and not in operators to test membership, and the append and pop methods to add and remove elements. Students also learn that lists cannot be combined with math or order comparison operators, unlike strings.

Status Status Type Title
List Operations
List Operations: quiz
Append
First Second
Last
Bookend List
Membership Test
Lengthy Question

This lesson explains mutability: whether a value can change in place, or whether only new values can be created from it. Students learn that strings, integers, floats and booleans are immutable while lists and dataclasses are mutable, and trace how a function can mutate a parameter passed into it.

Status Status Type Title
Mutability
Mutability: quiz
Lower Rent
Appending Strings
Repeat Louder
Wrong Return
Project 1: large programs and three-card poker

Exploring a large program

This series opens the first project with a program too large to take in at once, a word-guessing game. Students learn to decide whether to run unfamiliar code, explore it top-down or bottom-up by listing its functions and their calls, read its docstrings and external documentation, and trace a whole execution step by step.

Status Status Type Title
Project 1: overview
Large Programs
Exploring
Documentation
Stepping

Improving a large program

This series improves the word-guessing game from the previous series. Students learn to decompose and inline functions, choose clear, correct, concise, consistent and conventional names, replace magic numbers with constants, and extend the tests with branch coverage, edge cases and Drafter’s automatic tests, ending with the corrected program.

Status Status Type Title
Decomposition
Names
More Testing
Completion

Cards and hands

This series opens the three-card poker project with the game’s rules and scoring system. Students then write and test functions that convert a hand to a string, sort a hand, and detect a triple, a straight, and a pair, each a milestone toward the finished game.

Status Status Type Title
Instructions
hand_to_string
sort_hand
has_triple
has_straight
has_pair

Scoring and playing

This series completes the three-card poker project. Students write a function that scores a hand from its feature and card values, a function deciding whether the dealer plays, and a play_round function tying the rules together, then assemble and run the finished game and read a web interface for it built with Drafter.

Status Status Type Title
score_hand
dealer_plays
Testing play_round()
Play the Game
Drafter UI
For loops

This lesson introduces the for loop: its syntax, how the iteration variable is drawn from the iteration list, and how the loop body runs once per element. Students trace variable values across a for loop and write loops that process a list.

Status Status Type Title
For Loops: overview
For Loops: overview quiz
For Loops
For Loops: quiz
Hello Names
To Your Credit
Temperature Conversions
For With Function
Replacing In Loops

For loop patterns 1

This lesson covers the count, sum, accumulate, map and filter loop patterns for combining a for loop with an accumulator variable. Students use filter to remove or count only elements meeting a condition, and map to build a new list from an existing one.

Status Status Type Title
For Loop Patterns 1
For Loop Patterns 1: quiz
Missing Iter
Cube Elements
Sum High
Filter High
All For One

For loop patterns 2

This lesson continues the loop patterns with find, take and min/max, built around a condition checked inside the loop. Students use find to locate a matching element, take to copy elements until a condition is met, and min/max, guarded against an empty list, for the highest or lowest value.

Status Status Type Title
For Loop Patterns 2
For Loop Patterns 2: quiz
Find Fruits
Take
Minimum
Maximum Odd

Loop composition

This lesson covers loop composition: building a function from existing helper functions, such as sum and count, instead of one loop doing everything at once. Students compose given functions into new ones, define their own helper functions, and decide the order they must be called in.

Status Status Type Title
Loop Composition
Loop Composition: quiz
Average Problem
Existing Functions
New Functions
Highest Filter

Debugging loops

This lesson is about finding faults in loop-based code. Students debug two versions of a function that finds the biggest bed of flowers in a string, one built from helper functions and one with a single loop, each with four small bugs to locate and fix.

Status Status Type Title
Debugging loops: instructions
Flower Garden Version 1
Flower Garden Version 2

Loop patterns reference

This series is a single reference reading, not a lesson with exercises. It lists the loop patterns from this chapter, count, sum, accumulate, map, filter, find, take and min/max, each with its code template, for students to consult while working the chapter’s exercises.

Status Status Type Title
Reference (Loop Patterns)
Sequences

Lists and indexes

This lesson opens the sequences chapter and introduces indexing a list directly, using len, range and enumerate to generate and pair up indexes instead of iterating over values. Students update elements through their index and swap elements with multiple assignment.

Status Status Type Title
Sequences: overview
Sequences: overview quiz
Lists and Indexes
Lists and Indexes: quiz
Swap Ends
Double Mutation
Add Pairs
Make Cards

String iteration

This lesson covers iterating over strings, comparing them to lists, splitting a string into substrings with split, and looping over either its characters or the chunks split produces. Students combine these with the sum pattern to process comma-separated data and user input.

Status Status Type Title
String Iteration
String Iteration: quiz
Sum String
Animal Splits
Hot Cold
Sum User Input

Filesystems and files

This lesson covers files and the filesystem: absolute and relative paths, the current working directory, and the ls, cd and pwd commands, then opening, reading and closing a file in Python. Students process a file line by line, convert and clean the values they read, and debug a FileNotFoundError.

Status Status Type Title
Filesystems
Filesystems: quiz
Files
Files: quiz
Basic Files
Redacted
Adding Up

This series continues the files lesson with more exercises, without introducing new reading material. Students process files in different shapes: a one-line file read character by character, structured lines split into names, a whole file counted for its characters, and one file’s word list applied to another.

Status Status Type Title
Plus Or Minus
Fix Names
File Size
Madlibs
Nesting data

Lists of dataclasses

This lesson introduces lists of dataclasses, where each list element is a dataclass instance representing one record. Students learn to iterate over such a list, access fields of individual elements, and write functions that consume and return a list of dataclasses using loop patterns such as filter and sum.

Status Status Type Title
Nesting Data: overview
Nesting Data: overview quiz
Lists of Dataclasses
Lists of Dataclasses: quiz
Get Groceries
Check for Sales
Wish for Wings
Good Job

Nested dataclasses

This lesson covers dataclasses nested inside other dataclasses, including the rule that a referenced dataclass must be defined first. Students learn to chain attribute access across nesting levels, use temporary variables to unpack deeply nested data, and store a list inside a dataclass field.

Status Status Type Title
Nested Dataclasses
Nested Dataclasses: quiz
A Different Event
Flip the Switch
Combine Trips

This lesson covers lists nested inside lists, used to represent a grid or table of values of a single type. Students learn to write nested for loops to iterate, accumulate, and map over a two-dimensional list, access and update elements by row and column index, and decompose grid operations into helper functions.

Status Status Type Title
Nested Lists
Nested Lists: quiz
Zero Out Matrix
Render Lights
Captain Sails Again!

Heavily nested data

This lesson covers data nested arbitrarily deeply, combining lists and dataclasses across multiple layers. Students learn to read a class diagram of such a structure, use for loops, indexing, and chained attribute access to process it, and break long attribute chains into temporary variables and helper functions.

Status Status Type Title
Heavily Nested Data
Heavily Nested Data: quiz
Total Rainfall
Rainy, Cloudy Days

This lab has students write functions that process one shared, heavily nested dataclass structure describing a Halloween party, with fields for the party itself, its monsters, media, potions, and ingredients. It exercises attribute access, list iteration, and loop patterns such as filter and find across several layers of nesting, using dataclasses and test data already provided.

Status Status Type Title
Monster Mash: instructions
Get Party Ratio
Average Spookiness
Last Song
Longest Movie
Brew Time per Ingredient
Get Rarest Potion
Project 2: example programs, encryption and hashing

Ghost Hunter and Protein Lookup

This series opens the second project with complete example programs built with the Drafter web-app library. Students read a ghost-hunting tile game that keeps its board in a nested list and a food lookup that loads a tab-separated data file, and check with a quiz how each program’s functions, loop patterns and routes fit together.

Status Status Type Title
Project 2: overview
Ghost Hunter
Ghost Hunter: quiz
Protein Lookup
Protein Lookup: quiz

Commenter and Todo List

This series continues with two more Drafter example programs: a tool that annotates code line by line and a to-do list that creates, reads, updates and deletes its items. Students trace how each program keeps its state in a dataclass, which functions call which, and where the familiar loop patterns appear.

Status Status Type Title
Commenter
Commenter: quiz
Todo List
Todo List: quiz

This lesson opens the encryption and hashing project and introduces the ASCII table, which assigns every printable character a number. Students learn to convert between characters and their codes with the ord and chr functions, the groundwork for the rotation and hashing formulas built in the project’s later lessons.

Status Status Type Title
Instructions
Ascii Table
Ascii Table: quiz

Character rotation

This lesson covers a Caesar cipher that encrypts and decrypts text by rotating each character’s ASCII code by a fixed amount, wrapping around with the modulo operator. Students implement the encrypt_text and decrypt_text functions as the project’s second milestone.

Status Status Type Title
Character Rotation
Character Rotation: quiz
encrypt_text/decrypt_text

This lesson covers hashing: turning text into a short number with a formula based on each character’s position and code. Students implement the hash_text function, then a main function that ties encryption, decryption, and hashing together into one menu-driven program, and finally read a Drafter web interface for the finished tools.

Status Status Type Title
Hashing Values
Hashing Values: quiz
hash_text
Main Function
Drafter UI
While and plotting

This lesson introduces the while loop as a second form of iteration alongside the for loop, driven by a condition rather than a fixed sequence. Students learn to trace a while loop’s execution, recognize and avoid an infinite loop, and decide when a for loop is the safer choice instead.

Status Status Type Title
While and plotting: overview
While Loops
While Loops: quiz
No While Loops

While loop patterns

This lesson covers common while loop patterns: counting with a non-sequential step, walking through a list by index, the do-until loop, repeatedly prompting for and validating user input, rerolling random values, and a main game or server loop. Students learn to trace a while loop’s user-driven or stochastic behavior and pick the right pattern for a given problem.

Status Status Type Title
While Loop Patterns
While Loop Patterns: quiz
While Input
Doubling Down
Rainfall Accumulates

This lesson introduces data visualization with matplotlib, covering histograms, line plots, and scatter plots, and how to label a graph’s axes and title. Students write functions that build a requested plot from a list of numbers or a list of dataclasses, graded on the figure their code produces.

Status Status Type Title
Plotting
Plotting: quiz
Basic Histogram
Plotting Dataclasses
Plotting a Parabola
Plotting a Running Sum
Basic Scatter Plot
Time and trees

Time complexity and sorting

This lesson introduces time complexity and the sorting and searching problems. Students learn to estimate a program’s running time with the RAM model, classify code as constant, linear, or quadratic, compare linear and binary search, and trace the bubble sort and insertion sort algorithms.

Status Status Type Title
Time and trees: overview
Time Complexity
Time Complexity: quiz
Sorting
Sorting: quiz

Recursion and trees

This lesson introduces recursion, where a function calls itself on a smaller version of its input until it reaches a base case, and binary trees defined with dataclasses and inheritance. Students learn to trace and write recursive functions that process a tree’s nodes, following the branch, recursive call, and combination structure.

Status Status Type Title
Recursion and Trees
Recursion and Trees: quiz
Define Data
Debug Tree
Fill Tree
Evaluate Operator
Data

This lesson introduces dictionaries, which map keys to values: dictionary literals, looking up, updating and deleting items, membership tests, and iterating over keys, values and items. Students learn the common dictionary patterns, and when looking up a key in a dictionary beats finding an element in a list.

Status Status Type Title
Data: overview
Dictionaries
Dictionary Operations
Dictionary Patterns
Lookup vs Find

Dictionary records

This lesson covers special arguments, such as keyword and default arguments, *args and **kwargs, and unpacking a list or a dictionary into a call. Students then use dictionaries as records, convert between dictionaries and dataclasses with asdict, and read and write JSON data as strings and files.

Status Status Type Title
Special Arguments
Dictionary Records
JSON
Appendix