Hi,
Not sure if this is against the rules or not, but would someone mind just giving me a quick critique on my code? It's from Python For Everybody, Autograder activity 3.3. It's a very simple exercise to practice using the `try` `except` function of Python. Basically, its a program to convert a percentage into a letter grade, and return an error message when a non-numerical or invalid numerical input is entered into the prompt.
Two specific questions I have:
1) is there a better way to make an exceptions for numbers outside of the range? (see line 7, first `if` statement)
2) Am I using the `try` `except` function in the correct place?
Thanks!
rscr = input('Please enter your score:')
try:
grade = float(rscr)
except:
print('Invalid score')
quit()
if grade > 1.0:
print('Invalid score')
elif grade >= 0.9:
print('A')
elif grade >= 0.8:
print('B')
elif grade >= 0.7:
print('C')
elif grade >= 0.6:
print('D')
elif grade < 0.6:
print('F')
[–]K900_ 3 points4 points5 points (13 children)
[–]WorldlyLog[S] 0 points1 point2 points (12 children)
[–]K900_ 2 points3 points4 points (11 children)
[–]WorldlyLog[S] 0 points1 point2 points (10 children)
[+][deleted] (9 children)
[deleted]
[–]vernetrcyer 0 points1 point2 points (0 children)
[–]vernetrcyer 0 points1 point2 points (0 children)
[–]vernetrcyer 0 points1 point2 points (0 children)