初学者Python。循环和结束功能

时间:2017-08-25 22:31:33

标签: python loops

我所学的是非常基础的。我已经从我正在学习的书中编写了一个简短的程序,我想稍微修改它,以便你可以再次循环使用结束函数而不是简单的回答一次,程序结束。这就是我所拥有的:

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")

追踪(最近一次通话):   文件&#34; C:\ TheseusP&amp; GS \ Python \ teaching_your_kids_code \ what_my_grade.py&#34;,第4行,in     如果等级&gt; = 90: TypeError:&#39;&gt; =&#39; &#39; str&#39;的实例之间不支持和&#39; int&#39;

这是我接受的错误。

1 个答案:

答案 0 :(得分:0)

您正在将字符串和int与&gt; =进行比较。相反,这样做。

grade=input("Enter the number of your grade (0-100):")
while grade !="end":
    grade = int(grade)
    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")