QUESTION IMAGE
Question
answer = input(how wide is it? )\
width = float(answer)\
try:\
if width > 30:\
raise toowide\
else:\
print(\have a nice trip!\)\
toowide:\
print(\your luggage will not fit in the overhead bin.\)
Step1: Identify error
The code has an error because TooWide is not defined before the raise statement. In Python, when you raise an exception, it must be an existing exception class or an instance of an exception class.
Step2: Fix the code
To fix it, you can define TooWide as a custom exception class. For example:
class TooWide(Exception):
passSnap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
= input('How wide is it? ')
width = float(answer)
try:
if width > 30:
raise TooWide
else:
print("Have a nice trip!")
except TooWide:
print("Your luggage will not fit in the overhead bin.")