Foundations Beginner
Python uses indentation to define blocks. Missing colons or inconsistent spaces cause immediate errors.
In [1] Code cell pyodide
Run Collapse
Mini challenge: Write an if block that prints two indented lines, then one final line outside the block.
Foundations Beginner
print() helps you inspect values and explain what your program is doing.
In [2] Code cell pyodide
Run Collapse
Mini challenge: Print your name, grade level, and a sentence using an f-string with two values.
Foundations Beginner
Readable code is easier to debug and maintain. Comments explain why code exists, not obvious steps.
In [3] Code cell pyodide
Run Collapse
Mini challenge: Write a short 3-5 line program with one helpful comment and clear variable names.
Variables and Types Beginner
Good names make code self-explanatory. Reassignment lets a value change as your program runs.
Common syntax variations
name = 'Ava' score = 72 score = score + 1 score += 1 In [4] Code cell pyodide
Run Collapse
Mini challenge: Create variables for your name and age, print them, then reassign age to age + 1 and print again.
Variables and Types Beginner
Every value has a type. Understanding types helps prevent bugs and makes conversions predictable.
Common syntax variations
age = 12 # int height = 5.1 # float name = 'Mina' # str is_active = True # bool middle_name = None # NoneType In [5] Code cell pyodide
Run Collapse
Mini challenge: Create one variable of each type (int, float, str, bool, None) and print each variable with its type.
Variables and Types Beginner+
Some values can be changed in place (like lists), while others create a new value (like strings).
In [6] Code cell pyodide
Run Collapse
Mini challenge: Create a string and a list, modify both, and explain in a comment which one changed in place.
Variables and Types Beginner+
input() returns text. Converting values correctly is required for math and comparisons.
Common syntax variations
raw = input('Enter a number: ') number = int(raw) decimal = float(raw) text = str(number) In [7] Code cell pyodide
Run Collapse
Mini challenge: Read a number with input(), convert it to int, and print that number multiplied by 3.
Variables and Types Beginner
input() lets your program react to user choices.
In [8] Code cell pyodide
Run Collapse
Mini challenge: Ask for a user's name and favorite number, then print number + 10 and number * 2.
Operators and Logic Beginner
Arithmetic operators power totals, counters, and formulas.
In [9] Code cell pyodide
Run Collapse
Mini challenge: Choose two numbers and print their sum, product, remainder, and exponent result.
Operators and Logic Beginner
Comparisons and logic are the basis of decision-making.
In [10] Code cell pyodide
Run Collapse
Mini challenge: Create two boolean conditions and print results using and, or, and not.
Operators and Logic Beginner+
Use membership to check if a value appears in data and identity to compare object identity.
In [11] Code cell pyodide
Run Collapse
Mini challenge: Create two lists with the same values and compare them using == and is. Print both results.
Operators and Logic Beginner
Operators like += and -= make update logic cleaner and less error-prone.
In [12] Code cell pyodide
Run Collapse
Mini challenge: Start with a variable set to 20, then use +=, *=, and -= once each. Print after every step.
Conditionals Beginner
Conditionals let your code make choices.
In [13] Code cell pyodide
Run Collapse
Mini challenge: Create a program that prints beginner/intermediate/advanced based on a numeric level.
Conditionals Beginner+
Nested conditionals let you make decisions in stages.
In [14] Code cell pyodide
Run Collapse
Mini challenge: Write a nested conditional for a game: check level first, then check if player has a key.
Conditionals Beginner+
A ternary expression is a compact way to choose one of two values.
In [15] Code cell pyodide
Run Collapse
Mini challenge: Use a ternary expression to print pass/fail based on whether score is at least 70.
Loops Beginner
range() gives controlled sequences for counted repetition.
Common syntax variations
for i in range(stop): for i in range(start, stop): for i in range(start, stop, step): for i in range(10, 0, -1): In [16] Code cell pyodide
Run Collapse
Mini challenge: Use range() to print even numbers from 2 to 20.
Loops Beginner+
for loops work with many iterable types, not just range().
Common syntax variations
for ch in 'python': for item in ['a', 'b', 'c']: for key in my_dict: for key, value in my_dict.items(): In [17] Code cell pyodide
Run Collapse
Mini challenge: Create a dictionary for a book (title, pages, author) and loop through its items.
Loops Beginner
while loops repeat while a condition stays true.
Common syntax variations
while condition: while count > 0: while True: if should_stop:
break In [18] Code cell pyodide
Run Collapse
Mini challenge: Write a while loop that prints numbers from 1 to 8 and also prints their double.
Loops Beginner+
These control statements let you skip work, stop loops early, or mark unfinished code.
In [19] Code cell pyodide
Run Collapse
Mini challenge: Loop from 1 to 12, skip multiples of 3, and stop completely once you reach 10.
Loops Beginner+
Nested loops handle grid-like and pairwise problems.
In [20] Code cell pyodide
Run Collapse
Mini challenge: Use nested loops to print a 5x5 multiplication table (or as much as you can).
Loops Beginner+
A loop's else runs only when the loop finishes normally (not when break is used).
In [21] Code cell pyodide
Run Collapse
Mini challenge: Search for a value in a list using for + else and print either found or not found.
Functions Beginner
Functions make code reusable and easier to test.
In [22] Code cell pyodide
Run Collapse
Mini challenge: Write a function `triple(n)` that returns n * 3, then call it with at least two values.
Functions Beginner+
Variables created inside a function stay local unless explicitly returned.
In [23] Code cell pyodide
Run Collapse
Mini challenge: Create a function that uses a local variable and returns it. Print the returned value outside.
Data Structures Beginner
Lists store ordered, changeable collections of values.
In [24] Code cell pyodide
Run Collapse
Mini challenge: Create a list of 5 foods, replace one item, append one item, then loop and print all items.
Data Structures Beginner
Strings are text values you can slice, format, and inspect.
In [25] Code cell pyodide
Run Collapse
Mini challenge: Store a sentence and print: first character, last character, and the sentence in uppercase.
Data Structures Beginner+
Dictionaries map keys to values, and tuples store fixed groups of values.
In [26] Code cell pyodide
Run Collapse
Mini challenge: Make a dictionary with name and favorite_color, then add age and print all key/value pairs.
Foundations Beginner
Imports let you use code from Python and third-party libraries instead of rewriting everything.
Common syntax variations
import random import math as m from math import sqrt import pygame, random In [27] Code cell pyodide
Run Collapse
Mini challenge: Import random and print one random number from 1 to 10. Then import sqrt and print sqrt(81).
Operators and Logic Beginner+
Python treats many values as true/false, and and/or stop early. This affects real program behavior.
Common syntax variations
if value: if not value: result = user_name or 'Guest' is_ready = has_account and has_permission In [28] Code cell pyodide
Run Collapse
Mini challenge: Create three variables (one empty, one non-empty, one number) and print their bool() values. Then use or for a fallback label.
Loops Beginner+
List comprehensions are a compact way to build transformed or filtered lists used often in game code.
Common syntax variations
squares = [n * n for n in nums] evens = [n for n in nums if n % 2 == 0] In [29] Code cell pyodide
Run Collapse
Mini challenge: From numbers 1-12, build a list of multiples of 3 and another list with each number doubled.
Loops Beginner+
any() and all() are clean ways to answer yes/no questions across a collection.
Common syntax variations
any(score >= 90 for score in scores) all(ch.isalpha() for ch in text) In [30] Code cell pyodide
Run Collapse
Mini challenge: Create a list of temperatures and print whether any are below 32 and whether all are below 100.
Operators and Logic Beginner+
Clamping keeps values inside boundaries, which is essential for positions, health bars, and counters.
Common syntax variations
smallest = min(values) largest = max(values) x = max(0, min(limit, x)) In [31] Code cell pyodide
Run Collapse
Mini challenge: Clamp a score variable so it stays between 0 and 100, then print before and after.
Loops Beginner+
enumerate() gives index + value together, which is perfect for menus, grids, and ordered displays.
Common syntax variations
for index, item in enumerate(items): for index, item in enumerate(items, start=1): In [32] Code cell pyodide
Run Collapse
Mini challenge: Create a list of 4 tasks and print them as a numbered list starting at 1.
Data Structures Beginner+
Unpacking makes code cleaner when values naturally travel in pairs or grouped returns.
Common syntax variations
x, y = (10, 20) name, score = 'Ava', 95 a, b = b, a In [33] Code cell pyodide
Run Collapse
Mini challenge: Store three coordinate pairs in a list and loop with unpacking to print each x and y.
Data Structures Beginner+
Using .get() avoids crashes from missing keys and keeps programs resilient to incomplete data.
Common syntax variations
value = data.get('key') count = data.get('count', 0) In [34] Code cell pyodide
Run Collapse
Mini challenge: Create a dictionary for a user profile and print a missing field with a default value using .get().
Functions Beginner+
Classes bundle related data and behavior, and help you read APIs like pygame.Rect with confidence.
Common syntax variations
class Pet: def __init__(self, name): self.name = name pet = Pet('Luna') In [35] Code cell pyodide
Run Collapse
Mini challenge: Create a class with two attributes and one method, then create one object and call the method.
Foundations Beginner
Turtle gives immediate visual feedback and makes loops, angles, and functions feel concrete.
Common syntax variations
import turtle pen.forward(80) pen.left(90) pen.penup() / pen.pendown() turtle.done() In [36] Code cell pyodide
Run Collapse
Mini challenge: Use turtle to draw a triangle and a square in different colors. Use at least one loop.
Data Structures Beginner+
Sets automatically remove duplicates and support fast membership checks.
In [37] Code cell pyodide
Run Collapse
Mini challenge: Create a set from a list with duplicate names and print the cleaned set and its length.
Debugging Beginner
Fast debugging comes from reading error messages and checking assumptions one line at a time.
In [38] Code cell pyodide
Run Collapse
Mini challenge: Intentionally cause one NameError or TypeError, then fix it and write a one-line note about the fix.