这是我试图运行的代码。。。你知道吗
scoreCount = int(input("How many scores do you want to record?"))
recordedValues = 0
averageScore = totalScore/scoreCount
highestScore = 0
totalScore = 0
while recordedValues <= scoreCount:
score = int(input("\n\nEnter Score,:")
if type(score)== int:
totalScore == totalScore + score
recordedValues == recordedValues + 1
if score >= highestScore:
highestScore = score
else:
print("\n\nThe scores are not integer values")
quit()
如何结束while循环并显示平均分数/最高分数/记录的值?你知道吗
代码中有很多问题:在定义
totalScore
之前尝试将averageScore
赋值给totalScore/scoreCount
,有时使用==
等式检查器作为赋值运算符,检查score
是否在int
中,即使它已经被转换,while循环中的条件也有问题。以下是您可以做的:用异常处理替换重复的类型测试,并删除非法的变量赋值:
将
>=
更改为>
以获得最高分数,修复变量赋值,并用异常处理替换不需要的类型检查。你知道吗在while循环中放入==而不是=:
所以“recordedValues”和“totalScore”没有改变。你知道吗
编辑:“khelwood”已经在评论中提到了它。你知道吗
相关问题 更多 >
编程相关推荐