【发布时间】:2018-02-04 00:32:06
【问题描述】:
我所学的是非常基础的。我从我正在学习的一本书中编写了一个简短的程序,我想稍微修改它,以便您可以再次循环并使用结束函数而不是简单的回答一次,程序结束。这就是我所拥有的:
WhatsMyGrady.py
grade=eval(input("Enter the number of your grade (0-100):"))
while grade !="end":
if grade>=90:
print("You got an A!:)")
elif grade>=90:
print("You got a B!")
elif grade>=80:
print("You got a C.")
elif grade>=70:
print("You got a D...")
elif grade>=60:
print("you got an F.")
elif grade<59:
print("You Fail!")
grade=input("select another grade or enter 'end' to quit")
Traceback(最近一次调用最后一次): 文件“C:\TheseusP&GS\Python\teaching_your_kids_code\what_my_grade.py”,第 4 行,在 如果等级>=90: TypeError:“str”和“int”的实例之间不支持“>=”
这是我收到的错误。
【问题讨论】:
-
1:
grade = int(input("Enter the number of your grade (0-100):")),2:两次条件grade >= 90。 -
不要不要使用
eval(input(...))