【问题标题】:Invalid Syntax on Except TypeError? [closed]除了 TypeError 的语法无效? [关闭]
【发布时间】:2018-04-15 02:00:00
【问题描述】:

为什么我会在除了 TypeError 之外得到一个无效的语法,我该如何解决?

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"

【问题讨论】:

标签: python python-2.7 try-except


【解决方案1】:
    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 应该正好在“try”之下。你没有在 try 下添加,所以语法无效

【讨论】:

  • @Mandarin Orang:如果这是您所期望的,请确认这是您需要的答案
猜你喜欢
  • 2015-01-08
  • 1970-01-01
  • 2014-08-22
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 2022-07-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多