测试分数程序-Python

测试分数程序-Python,python,python-3.x,Python,Python 3.x,我应该创建一个程序,使用用户的输入创建一个平均测试分数。我还需要确保当用户说“结束”而不是输入一个分数时,程序会使用break并将结果提供给用户。但是,我无法让程序正确运行,需要一些输入 #!/usr/bin/env python3 #display a welcome message print("The test Scores program") print() print("Enter end to stop input") #change from 999 to end print("

我应该创建一个程序,使用用户的输入创建一个平均测试分数。我还需要确保当用户说“结束”而不是输入一个分数时,程序会使用break并将结果提供给用户。但是,我无法让程序正确运行,需要一些输入

#!/usr/bin/env python3

#display a welcome message
print("The test Scores program")
print()
print("Enter end to stop input") #change from 999 to end
print("========================")
print()

#variables
counter = 0
score_total = 0
test_score = 0

choice = "y"

while choice.lower():
    while True:
        test_score =input("Enter test score: ")

        if test_score == "end":
            break
        elif (test_score >= 0) and (test_score <= 100):
            score_total += test_score
            counter += 1
        else:
            print("Test score must be from 0 through 100. Try again>")

    #calculate average score
    average_score = round(score_total / counter)

    #display result
    print("=======================")
    print("Total Score: ", score_total)
    print("Average Score: ", average_score)
    print()

    #see if user wants to continue
    choice = input("Continue (y/n)? ")
    print()

print("Bye")
#/usr/bin/env蟒蛇3
#显示欢迎信息
打印(“考试分数计划”)
打印()
打印(“输入结束到停止输入”)#从999更改为结束
打印(“=====================================”)
打印()
#变数
计数器=0
总分=0
测试分数=0
choice=“y”
while choice.lower():
尽管如此:
测试分数=输入(“输入测试分数:”)
如果测试分数=“结束”:
打破

elif(test_score>=0)和(test_score当您执行
(test_score>=0)和(test_score=0)和(int(test_score)时,您正在比较字符串和int(test_score>=0)和(test_score=0)和(int(test_score)已经很晚了,但这是为碰巧有相同问题的人准备的。您可以尝试将“int”与测试分数=输入分开(“输入测试分数:):)

为True时:
测试分数=输入(“输入测试分数:”)
如果测试分数=‘结束’:
打破
测试分数=整数(测试分数)

如果0已经晚了,但这是为碰巧有相同问题的任何人准备的。您可以尝试将“int”与测试分数=输入分开(“输入测试分数:):)

为True时:
测试分数=输入(“输入测试分数:”)
如果测试分数=‘结束’:
打破
测试分数=整数(测试分数)

如果测试分数为非整数,则可以使用if 0
float
。如果测试分数为非整数,则可以使用
float
    test_score =input("Enter test score: ")

    if test_score == "end":
        break
    elif (int(test_score) >= 0) and (int(test_score) <= 100):
        score_total += int(test_score)
        counter += 1
    else:
        print("Test score must be from 0 through 100. Try again>")
while True:
        test_score = input("Enter test score: ")
        if test_score == 'end':
            break
        test_score = int(test_score)
        if 0 <= test_score <= 100:
            score_total += test_score
            counter += 1
    
        else:
            print(
                "Test score must be from 0 through 100. Score discarded. Try again."
            )