Skip to the content

Reading an error

Python · Unit 9: Errors and exceptions

When something goes wrong, Python stops and tells you three things: the error type, the line and a message. In the console it looks like this: ZeroDivisionError (line 3): division by zero.

The type is the name of the problem and the message is the detail. Together they tell you what to look for and where.

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Multiple choice

    Python shows NameError (line 4): name 'totl' is not defined. What happened?

  2. 2. Find the bug

    This program should add up the price and the tip. Which line has the bug?

  3. 3. Find the bug

    This program should greet Ana, say her age and welcome her. Which line has the bug?

  4. 4. Multiple choice

    A program has 5 lines and each one prints something. Line 3 crashes with TypeError. What do you see on the screen?

  5. 5. Find the bug

    Three friends split a bill of 450. The program should print how much each one pays. Which line has the bug?

  6. 6. Multiple choice

    Python says IndexError (line 5): list index out of range. What's true?

  7. 7. Find the bug

    This program should print the whole menu. Which line has the bug?

  8. 8. Multiple choice

    Which of these errors shows up before any line runs?

  9. 9. Complete the code

    Python said NameError (line 4): name 'Total' is not defined. Complete line 4 so it prints what you pay.

  10. 10. Predict the output

    Look closely at line 3. What does it print?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →