Python Adventure Assignments
Every zone teaches concepts — assignments make you use them. 10 guided coding assignments, two per new zone, where you write real Python by hand and check your own work.
📋 How These Assignments Work
Unlike the in-game levels, these are no multiple-choice — you write and run real Python 3 code, then grade yourself.
- 1Read the Goal. One or two sentences telling you what the finished program should do.
- 2Check the Requirements. A checklist of the concrete steps your code needs to cover.
- 3Fill in the Starter Code. Copy it into the Playground or a
.pyfile — there's one clear gap marked# TODOfor you to complete. - 4Run it and compare. Check what your program prints against the Expected Output example.
- 5Stuck? Open the Hint. Each assignment has one progressive hint — a nudge, not the answer.
10 Guided Assignments — Two Per Zone
🎯 Goal
Read through a server log file and count how many lines contain the word ERROR, using safe file handling with with open().
✅ Requirements
- Read the file using
with open() - Loop through the file one line at a time
- Check if the line contains the word
"ERROR" - Count how many lines matched
- Print the final count
💻 Starter Code
💡 Hint
with open("server.log") as f:, then loop for line in f: and use if "ERROR" in line: to check each line, adding 1 to error_count every time it matches.▶ Expected Output
🎯 Goal
Write a linear_search function that checks a list of numbers one at a time to find a target value and reports its position.
✅ Requirements
- Write a function
linear_search(numbers, target) - Loop through the list using an index (
for i in range(...)) - Return the index as soon as a match is found
- Return
-1if the loop finishes with no match - Call the function and print whether it was found
💻 Starter Code
💡 Hint
numbers[i] to target with if numbers[i] == target: — the moment they match, return i immediately instead of continuing the loop.▶ Expected Output
🎯 Goal
Write your own small module with a function inside it, import that function into a second script, and prove it works with an assert test.
✅ Requirements
- Create a function
make_greeting(name)that returns a string - Save it in its own file,
greetings.py— that file is your module - In a second file, import the function with
import greetings - Write one
assertstatement that checks the function's output - Print a greeting using the imported function
💻 Starter Code
Save as greetings.py:
Save as main.py, in the same folder:
💡 Hint
greetings.py, use an f-string: return f"Hello, {name}! Great to see you." In main.py, call it exactly like a built-in function, but with the module name in front: greetings.make_greeting("Ada").▶ Expected Output
🎯 Goal
Parse a block of JSON text that looks like it came from a weather API, then print specific fields like the temperature and condition.
✅ Requirements
- Import the
jsonmodule - Use
json.loads()to turn the JSON string into a dictionary - Print the city name
- Print the temperature
- Print the weather condition
💻 Starter Code
💡 Hint
json.loads(weather_json) turns JSON text into a normal Python dictionary — then you can grab a field with square brackets, like weather["city"].▶ Expected Output
🎯 Goal
Combine two skills from earlier assignments: write a function that formats one receipt line, then save several formatted lines to a file.
✅ Requirements
- Write a function
format_item(name, price)that returns a formatted string - Call the function for at least 3 items
- Write all the formatted lines to a file called
receipt.txtwithwith open() - Print a confirmation message with the number of items saved
💻 Starter Code
💡 Hint
return f"{name} - ${price:.2f}" — the :.2f makes sure the price always shows exactly two decimal places, even for whole numbers.▶ Expected Output
receipt.txt will contain:
Apple - $1.50
Bread - $3.20
Milk - $2.75
🎯 Goal
Read a messy text file, strip out any blank lines, and save the cleaned result to a brand new file.
✅ Requirements
- Read all lines from the messy file with
readlines() - Build a new list that only keeps non-blank lines
- Use
.strip()to treat whitespace-only lines as blank too - Write the cleaned lines to a new file,
clean.txt - Print how many blank lines were removed
💻 Starter Code
💡 Hint
lines and use if line.strip(): — an empty or whitespace-only string becomes "" after .strip(), which Python treats as "falsy", so this check skips blank lines automatically.▶ Expected Output
🎯 Goal
Implement bubble sort on a list of numbers, printing the list after every full pass so you can watch it gradually become sorted.
✅ Requirements
- Write a function
bubble_sort(numbers) - Use two loops: an outer loop for passes, an inner loop for comparisons
- Swap two neighboring numbers if they're in the wrong order
- Print the list after each full pass
- Print the final sorted list
💻 Starter Code
💡 Hint
pass with an if statement: if numbers[i] > numbers[i + 1]: then swap on the next line with numbers[i], numbers[i + 1] = numbers[i + 1], numbers[i]. Python can swap two variables in one line like that.▶ Expected Output
🎯 Goal
Write a decorator called timer that wraps any function and prints how many seconds it took to run.
✅ Requirements
- Import the
timemodule - Write a decorator function
timer(func)with an innerwrapperfunction - Record the start time before calling
func, and the end time after - Print the elapsed time using
func.__name__ - Apply the decorator to a sample function with
@timer
💻 Starter Code
💡 Hint
result = None with result = func(*args, **kwargs) — this actually runs the wrapped function with whatever arguments were originally passed in, and saves what it returns.▶ Expected Output
The exact time will be different on your computer — only the "Total:" line needs to match exactly.
🎯 Goal
Use the re module to search a block of text and pull out every email address it contains.
✅ Requirements
- Import the
remodule - Write a regex pattern that matches email addresses
- Use
re.findall()to find every match in the text - Print the list of emails found
- Print how many were found
💻 Starter Code
💡 Hint
r"[\w.+-]+@[\w-]+\.[\w.-]+" — it matches letters, numbers, dots, plus signs, and hyphens before the @, then a domain name that contains at least one dot. Use re.findall(pattern, text) to get every match as a list.▶ Expected Output
🎯 Goal
Write three assert tests for a function that checks whether a number is prime, so you can prove it works correctly before trusting it elsewhere.
✅ Requirements
- Use the provided
is_prime(n)function - Write 3
assertstatements that test different cases - Cover: a prime number, a non-prime number, and an edge case
- Add a helpful message to each assert so failures are easy to read
- Print
"All tests passed!"if nothing crashes
💻 Starter Code
💡 Hint
assert is_prime(7) == True, "7 should be prime", assert is_prime(10) == False, "10 should not be prime", and assert is_prime(1) == False, "1 is a classic edge case" — 1 is neither prime nor composite by definition.▶ Expected Output
Frequently Asked Questions
What's the difference between assignments and regular levels?
Do I need Python installed to do these assignments?
How do I know if I got an assignment right?
What if I get stuck on an assignment?
Do I need to finish the zone levels before doing the matching assignment?
How long does each assignment take?
🐍 Ready to Write Real Code?
Pick an assignment for a zone you've already played and open the Playground to start typing.
▶ Open Python Playground 🛠️ See the Mini-Projects →
Python Adventure