I am trying to break a while loop with user input "exit" in a try-except block where the input is converted to float.
My code currently looks like this:
def checkGrade():
while True:
try:
floatGrade = float(input("Enter student grade: "))
if floatGrade == 100:
return("A+")
# I go down the list of grades to F after this if.
except:
if floatGrade == "exit":
# This is where I want the code to break, but it gives me an error when I print the function def checkGrade()
break
else:
continue
I get an error
could not convert string to float: "exit"
Any thoughts? Thanks in advance for your help!