Introduction to Python and Google Colab: difficulty 2

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

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.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Introduction to Python and Google Colab Questions: