-5

why do I get an invalid syntax on except TypeError and how do I fix it?

Try:
score=float(raw_input("What is your score?"))
If score>100 or score<0:
print "please enter a score between 100 and 0"
except TypeError:
print "Please enter your score in digits"
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
  • I suggest you read the documentation: https://docs.python.org/3/tutorial/errors.html – cs95 Apr 15 '18 at 02:02

1 Answers1

2
    score = float(input("What is your score?\n"))
    try:
        if score > 100 or score < 0:
            print("please enter a score between 100 and 0")
        elif score >= 80:
            print("GPA is 8.0 and Grade is A+")
        elif score >= 70:
            print("GPA is 7.0 and Grade is A")
        elif score >= 65:
            print("GPA is 6.5 and Grade is B")
        elif score >= 60:
            print("GPA is 6.0 and Grade is C")
        elif score >= 55:
            print("GPA is 5.5 and Grade is D")
        elif score >= 50:
            print("GPA is 5.0 and Grade is E")
        else:
            print("GPA is 0 and Grade is O")
    except TypeError:
        print("Please enter your score in digits")

except should be exactly under 'try'. You didn't add under try so got invalid syntax

  • @Mandarin Orang: If this is what you are expecting, please confirm this as your required answer –  May 18 '18 at 01:01