This is probably a simple answer but I thought I'd ask anyway.
My code below is asking the user for a number and depending on the answer provided will print the grade that corresponds with the numbers.
I want to stop the loop (terminate the program) by having the user type in (999). I know the problem is in my if userScore >= 90" print ('A'). So when the user enters the 999, the computer takes it as an A.
Is there a shortcut to fix this?
(PS I added the breaks to every line because when they were not there the outputs kept repeating endlessly.)
userScore = float(input('Enter the score or type "999" to quit: '))
while True:
try:
if userScore >= 90:
print ("You earned an A")
break
elif userScore >= 80:
print ("You earned a B")
break
elif userScore >= 70:
print ("You earned a C")
break
elif userScore >= 60:
print ("You earned a D")
break
elif userScore <= 59.9:
print ("You earned an F")
break
except:
if userScore == '999':
break
main()
userScore == '999'first; right after thetry. By the way, why thetry?tryis generally used for error checking - I don't thinktryis the right syntax to use here. Just add anotherifstatement before your other ones that checks ifuserScore == '999'.