Python Python Basics All Together Now Wrap Up

Mercedes Aker
Mercedes Aker
4,079 Points

Python Basics quiz question

Quiz Question 5 of 5 There is a keyword missing that allows you to have access to the exception that was caught.

correct_answers = input("How many correct answers did you get? ") try: correct_answers = int(correct_answers) except ValueError ___ err: print("Whoops! Try again: {}".format(err)) What keyword is missing?

The answer to this quiz question was "as" but I don't understand where it goes in the code and why its needed. Any explaination?

1 Answer

Steven Parker
Steven Parker
186,966 Points

The "as" keyword causes the variable that follows it to be assigned with the data associated with the exception (known as the "exception argument"). In this example, it contains a string that gets included in the output message.