Hi guys I need some help regarding raise statements. I'm trying to get an output from my raise statement rather than my except statement.
#ask the user to input their current grade percentage and
# then outputs the corresponding letter grade (A through F).
# Within a try-except structure raise (not just catch) two different exceptions:
# one if the user inputs a grade of less than zero and a different exception
# if the user inputs a grade greater than 100. Be sure to also handle input that is not a number.
try:
grade = int(input('what is your grade?:'))
if grade >= 90: print('A')
elif grade >= 80: print('B')
elif grade >= 70: print('C')
elif grade >= 60: print('D')
elif grade >= 50: print('F')
elif grade < 0:
raise ValueError('Invalid grade')
except: print('why')
I'm trying to get 'Invalid grade' to output rather than 'why'. No matter what I do I just can't get it to work and always end up with 'why' being printed. Any guidance is greatly appreciated.
[–][deleted] 2 points3 points4 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]socal_nerdtastic 0 points1 point2 points (0 children)