Python 它不断地输出;失败;当它实际输出一个等级时 test_1=int(输入(“请输入测试1/100的分数:”) 测试2=int(输入(“请输入测试2/100的分数:”) 测试3=int(输入(“请输入测试3/100的分数:”) 测试4=int(输入(“请输入测试4/100的分数:”) 测试5=int(输入(“请输入测试5/100的分数:”) 总计=测试1+测试2+测试3+测试4+测试5 平均数=总数/5 打印(“总分为”,总计) 打印(“平均分数为”,平均) 如果平均值=100: 印刷品(“达到9级”) elif平均值=90: 印刷品(“达到8级”) elif平均值=80: 印刷品(“达到7级”) elif平均值=70: 印刷品(“六级成绩”) elif平均值=60: 印刷品(“达到5级”) elif平均值=50: 印刷品(“达到四级”) elif平均值=40: 印刷品(“达到三级”) elif平均值=30: 印刷品(“达到二级”) elif平均值=20: 打印(“达到1级”) 其他: 打印(“失败”)

Python 它不断地输出;失败;当它实际输出一个等级时 test_1=int(输入(“请输入测试1/100的分数:”) 测试2=int(输入(“请输入测试2/100的分数:”) 测试3=int(输入(“请输入测试3/100的分数:”) 测试4=int(输入(“请输入测试4/100的分数:”) 测试5=int(输入(“请输入测试5/100的分数:”) 总计=测试1+测试2+测试3+测试4+测试5 平均数=总数/5 打印(“总分为”,总计) 打印(“平均分数为”,平均) 如果平均值=100: 印刷品(“达到9级”) elif平均值=90: 印刷品(“达到8级”) elif平均值=80: 印刷品(“达到7级”) elif平均值=70: 印刷品(“六级成绩”) elif平均值=60: 印刷品(“达到5级”) elif平均值=50: 印刷品(“达到四级”) elif平均值=40: 印刷品(“达到三级”) elif平均值=30: 印刷品(“达到二级”) elif平均值=20: 打印(“达到1级”) 其他: 打印(“失败”),python,Python,我的代码运行得非常好,除了每次运行时,即使平均分数高于10,输出也会失败。如果s,您的链应更改为:1。逻辑正确。2.利用以前的ifs test_1 = int(input("Please enter the score for test 1 /100:")) test_2 = int(input("Please enter the score for test 2 /100:")) test_3 = int(input("Please enter the score for test 3

我的代码运行得非常好,除了每次运行时,即使平均分数高于10,输出也会失败。

如果s,您的
链应更改为:1。逻辑正确。2.利用以前的
if
s

test_1 = int(input("Please enter the score for test 1  /100:"))
test_2 = int(input("Please enter the score for test 2  /100:"))
test_3 = int(input("Please enter the score for test 3  /100:"))
test_4 = int(input("Please enter the score for test 4  /100:"))
test_5 = int(input("Please enter the score for test 5  /100:"))

total = test_1 + test_2 + test_3 + test_4 + test_5
average = total/5

print ("The total score is", total)
print ("The average score is", average)

if average < 90 and average >= 100:
    print ("Grade 9 achieved")
elif average < 80 and average >= 90:
    print ("Grade 8 achieved")
elif average < 70 and average >= 80:
    print ("Grade 7 achieved")
elif average < 60 and average >= 70:
    print ("Grade 6 achieved")
elif average < 50 and average >= 60:
    print ("Grade 5 achieved")
elif average < 40 and average >= 50:
    print ("Grade 4 achieved")
elif average < 30 and average >= 40:
    print ("Grade 3 achieved")
elif average < 20 and average >= 30:
    print ("Grade 2 achieved")
elif average < 10 and average >= 20:
    print ("Grade 1 achieved")
else:
    print ("Fail")

如果
s在逻辑上不正确,您的
。例:
平均值如何既小于90又大于100?
if average >= 90:
    print ("Grade 9 achieved")
elif average >= 80:
    print ("Grade 8 achieved")
elif average >= 70:
    print ("Grade 7 achieved")
elif average >= 60:
    print ("Grade 6 achieved")
elif average >= 50:
    print ("Grade 5 achieved")
elif average >= 40:
    print ("Grade 4 achieved")
elif average >= 30:
    print ("Grade 3 achieved")
elif average >= 20:
    print ("Grade 2 achieved")
elif average >= 10:
    print ("Grade 1 achieved")
else:
    print ("Fail")