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

Py

Your first Python program

What appears when Python evaluates this line?

Beginner
Py

Variables and values

Add 4 to the starting number and print the result. Try replacing the starting value for each case.

Beginner
Py

Numbers, operators, and conversion

How many full bins can you fill, and how many items remain?

Beginner
Py

Reading input and displaying results

What does `int("19") + 1` evaluate to?

Beginner
Py

Strings, slices, and formatting

Which characters does this slice return?

Beginner
Py

Decisions with if and else

Predict the room status for each number of seats left.

Beginner
Py

Loops and counters

Compute the sum of the whole numbers from 1 up to and including the input number.

Beginner
Py

Lists, indexes, and copies

What does a contain after the last line?

Beginner
Py

Tuples and sets

How many unique values are here?

Beginner
Py

Lists and dictionaries

Count the occurrences of moss in each list.

Beginner
Py

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.

Beginner
Py

Errors and input validation

Predict what parse_seats returns for each string.

Intermediate
Py

List and dictionary comprehensions

What does the positive-values doubling example produce?

Intermediate
Py

Modules, imports, and packages

What happens when another file imports total from prices?

Intermediate
Py

Files and JSON

After decoding, what is the Python value of done?

Intermediate
Py

Classes, instances, and dataclasses

Which object changes when you set the first book’s pages to 121?

Intermediate
Py

Type hints and data contracts

What can this function return at runtime?

Intermediate
Py

Virtual environments and dependencies

How can both versions live on the same computer?

Intermediate
Py

Positional and keyword arguments

Which value binds to message?

Intermediate
Py

Iterators and generators

What does list(g) contain?

Advanced