Python for a Coding Assessment
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
I can run a Python program in its own virtual environment and read a traceback to name the file and line that failed, the exception type, and what the message is telling me to change.
Nothing. This is a starting point.
The first twenty minutes of any Python work: an interpreter you can run, an environment that holds the right packages, and the ability to read what Python says when something breaks.
In scope: creating and activating a virtual environment, installing into it, running a script and a module, and reading a traceback. Out of scope: a debugger’s breakpoints and watch expressions, and packaging your own project, which come later.
A Python installation is shared; a virtual environment is yours. Without one, two projects fight
over the same package versions and the loser fails in a way that looks like a bug in your code.
python -m venv .venv creates a directory with its own interpreter and its own site-packages, and
activating it changes which python runs. Every instruction you will read from here on assumes you
are inside one.
Read it bottom up. The last line is the exception type and message — the fact. Above it, the stack is the path that got there, most recent call last, each frame naming a file, a line number and the line itself.
The frame at the bottom is where Python gave up, which is not always where you went wrong: a
TypeError deep inside a library usually means you passed it something wrong higher up. Walk up the
frames until you reach a file you wrote. That line is where to start.
Three messages worth recognising on sight:
NameError: name 'x' is not defined — a typo, or use before assignment, or a variable that
exists only inside another scope.TypeError: ... takes 2 positional arguments but 3 were given — a call that does not match the
signature, often self on a method called from the wrong place.IndexError: list index out of range — an index computed from a length without accounting for
zero-based counting, or an empty collection you assumed had items.python is running before touching anything.pip install installs for the project.” It installs for whichever interpreter is active. Out
of a virtual environment, that is the whole machine.Hand learners a short script that raises, rather than asking them to write one. Ask them to say aloud what the traceback claims before they touch the code — the habit of reading before editing is the whole outcome, and it transfers to every language.
A good check: break the same program in three ways and have the learner name each exception type from the message alone.
| Resource | Kind | Cost | Provider |
|---|---|---|---|
| The Python Tutorial: virtual environments and packages | reading | free | Python Software Foundation |
| The Python Tutorial: errors and exceptions | reading | free | Python Software Foundation |
| CS50P, week 0: functions and variables | video | free | Harvard University |
| Python Tutor, step-by-step execution | interactive | free | Python Tutor |
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
No assessment yet.
The holder can take an unfamiliar problem, write a tested Python solution someone else can run, and explain what it costs.
Nothing to show yet. The publisher last published on 2026-09-20, and no aggregate for this outcome has reached the 50 learners a number needs. Open Degree does not track learners. About learner evidence.