Reading an error
Python · Unit 9: Errors and exceptions
- Full plan
- Python
- 10 exercises
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. Multiple choice
Python shows
NameError (line 4): name 'totl' is not defined. What happened?2. Find the bug
This program should add up the price and the tip. Which line has the bug?
3. Find the bug
This program should greet Ana, say her age and welcome her. Which line has the bug?
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. 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. Multiple choice
Python says
IndexError (line 5): list index out of range. What's true?7. Find the bug
This program should print the whole menu. Which line has the bug?
8. Multiple choice
Which of these errors shows up before any line runs?
9. Complete the code
Python said
NameError (line 4): name 'Total' is not defined. Complete line 4 so it prints what you pay.10. Predict the output
Look closely at line 3. What does it print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.