Back to Lesson

Multiple Exceptions

Write a block with multiple exception handlers.

Instructions

  • Given
    data = {"a": "hello"}
    .
  • Inside a try block, try to access
    data["b"]
    and cast it to an
    int()
    on one line:
    num = int(data["b"])
    .
  • Add an except block for
    KeyError
    that prints
    "Key missing"
    .
  • Add an except block for
    ValueError
    that prints
    "Not a number"
    .
main.py
main.py