初级Python。循环和结束函数

2024-04-26 05:27:37 发布

您现在位置:Python中文网/ 问答频道 /正文

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

你知道吗什么MyGrady.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")

回溯(最近一次呼叫): 文件“C:\thesesp&GS\Python\teaching\u your\u children\u code\what\u my”_等级.py,第4行,在 如果等级大于等于90: TypeError:“>;=”在“str”和“int”的实例之间不受支持

这是我收到的错误。你知道吗


Tags: 函数py程序youaninputyour基础
1条回答
网友
1楼 · 发布于 2024-04-26 05:27:37

将字符串和int与>;=进行比较。相反,这样做。你知道吗

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

相关问题 更多 >