๐Ÿ
๐Ÿ“ Intermediate Python ยท PY-201 ยท Assignments

Intermediate Python โ€” Assignments

Work each problem yourself first, then open the worked solution to check your thinking. This is where the course sticks.

๐Ÿ“ 5 problemsโœ๏ธ Worked solutions
Problem 1

Take a longer script (yours or an example) and break it into well-named functions.

Show worked solution

A strong answer shows a blob split into small functions each doing one clear job, with names that read like sentences, and notes where repetition or an explanatory comment signalled a function was needed - demonstrating the organise-as-you-grow habit.

Problem 2

Write a program that saves some data to a JSON file and loads it back next run.

Show worked solution

Good answers use 'with open(...)' for both read and write, json.dump/load for the data, and handle the first-run case where the file doesn't exist yet (FileNotFoundError -> a sensible default) - showing files + error handling working together.

Problem 3

Show a good use of try/except and an example where you'd deliberately let code crash.

Show worked solution

Strong answers catch a SPECIFIC exception for something anticipated (bad input, missing file) and explain that a genuine bug or impossible data should crash loudly with a clear message rather than be swallowed - never 'except: pass'.

Problem 4

Design a small class (e.g. an account, a player, a cart) with attributes and methods.

Show worked solution

Good answers define __init__ setting up the object's data and a couple of methods that act on self, explain that self means 'this particular object', and justify why a class fits (data + behaviour belong together, or many instances needed).

Problem 5

Rewrite three pieces of code more Pythonically (a comprehension, unpacking, truthiness).

Show worked solution

Strong answers show a loop-and-append turned into a simple comprehension, index-juggling replaced by unpacking or enumerate, and 'if len(x) > 0' simplified to 'if x' - while noting that readability, not brevity, is the goal.

More in this course

Course home → · Browse all courses →