Previous Lesson Current Lesson Next Lesson

Question 1

raise OSError("Sorry about that! Something went wrong")

This will output:

OSError: Sorry about that! Something went wrong

Question 2

def f(x):
    if x == "cat":
        raise ValueError("Invalid input!")
    print("Good input!")

This is very similar to the example from the lesson, except with slightly different strings printed and a different invalid input.

Question 3

try:
    f("cat")
except ValueError:
    print("Uh oh! Something went wrong.")

print("Yay! We made it to the end!")

This will output:

Uh oh! Something went wrong.
Yay! We made it to the end!

Note that it is important to write ValueError after the except (or nothing after it) so that Python can handle the ValueError raised in your f function. Otherwise, the error raised will halt the program and not execute the print statement at the very end.