Mark Yourself Question
For each expression below, state exactly what Python produces - the value and its type, or the error raised. Then state the general rule that all six illustrate.
Unlock full course notes by signing up
Introduction to Python and Google Colab: difficulty 2
A student reopens a Colab notebook they wrote the previous day. Scrolling to the middle of it, they run a cell containing average = total_sales / n_months. Colab responds with NameError: name 'total_sales' is not defined.
The student is confident the notebook is correct, because a cell higher up the page plainly reads total_sales = 48200, and directly beneath it the saved output 48200 is still visible from yesterday.
Explain why the error occurs, give the immediate fix, and state the routine that prevents this class of problem.