Practice problems
Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.
Showing 1–20 of 24 problems
Your first Python program
What appears when Python evaluates this line?
Variables and values
Add 4 to the starting number and print the result. Try replacing the starting value for each case.
Numbers, operators, and conversion
How many full bins can you fill, and how many items remain?
Reading input and displaying results
What does `int("19") + 1` evaluate to?
Strings, slices, and formatting
Which characters does this slice return?
Decisions with if and else
Predict the room status for each number of seats left.
Loops and counters
Compute the sum of the whole numbers from 1 up to and including the input number.
Lists, indexes, and copies
What does a contain after the last line?
Tuples and sets
How many unique values are here?
Lists and dictionaries
Count the occurrences of moss in each list.
Functions and return values
Predict the full cost for each rider count, with a fare of 5 per person and an extra 2 per trip.
Errors and input validation
Predict what parse_seats returns for each string.
List and dictionary comprehensions
What does the positive-values doubling example produce?
Modules, imports, and packages
What happens when another file imports total from prices?
Files and JSON
After decoding, what is the Python value of done?
Classes, instances, and dataclasses
Which object changes when you set the first book’s pages to 121?
Type hints and data contracts
What can this function return at runtime?
Virtual environments and dependencies
How can both versions live on the same computer?
Positional and keyword arguments
Which value binds to message?
Iterators and generators
What does list(g) contain?