Common errors
Python · Unit 9: Errors and exceptions
- Full plan
- Python
- 10 exercises
NameError: you use a name that doesn't exist, because it's misspelled or hasn't been created yet.
TypeError: the operation doesn't work with that kind of data, like text plus a number, or calling a function without the arguments it needs.
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
Your function is
def greet(name):and you call it withgreet(). Python saysTypeError: greet() missing 1 required positional argument: 'name'. What happened?2. Find the bug
This program should print the triangle's area. Which line has the bug?
3. Complete the code
Complete it to count how many digits the number has.
4. Multiple choice
The person types seven, in letters, and the program does
int(input()). What error comes out?5. Complete the code
The price comes in as text. Complete it to convert it and work out double.
6. Find the case that fails
per_person(total, people)should return how much each person pays, or0if there's nobody. Which call breaks it?7. Find the bug
This program should print every grade. Which line has the bug?
8. Multiple choice
Python says
KeyError: 'Leo'. What happened?9. Multiple choice
Every line crashes. Which one gives
ValueError?10. Predict the output
This program guards against two errors. 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.