Skip to the content

Common errors

Python · Unit 9: Errors and exceptions

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. 1. Multiple choice

    Your function is def greet(name): and you call it with greet(). Python says TypeError: greet() missing 1 required positional argument: 'name'. What happened?

  2. 2. Find the bug

    This program should print the triangle's area. Which line has the bug?

  3. 3. Complete the code

    Complete it to count how many digits the number has.

  4. 4. Multiple choice

    The person types seven, in letters, and the program does int(input()). What error comes out?

  5. 5. Complete the code

    The price comes in as text. Complete it to convert it and work out double.

  6. 6. Find the case that fails

    per_person(total, people) should return how much each person pays, or 0 if there's nobody. Which call breaks it?

  7. 7. Find the bug

    This program should print every grade. Which line has the bug?

  8. 8. Multiple choice

    Python says KeyError: 'Leo'. What happened?

  9. 9. Multiple choice

    Every line crashes. Which one gives ValueError?

  10. 10. Predict the output

    This program guards against two errors. 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 →