首页 > 解决方案 > 我不明白这个循环,我死在里面

问题描述

编写一个程序,提示 10 个测验(每个最多 10 分)和 10 个小项目(每个最多 20 分)的分数。提示这些时,您必须使用循环。请务必检查每个答案是否在范围内。

我无法理解如何去做。我写的代码没有输出正确的答案。

total=0
total2=0
for x in range(10):
        num1 = int(input("Please enter quiz score: "))
        if num1 > 10:
            print("This number is outside of the allotted range. Ignoring.")
for x in range(10):
        num2 = int(input("Please enter mini project score: "))
        if num2 > 20:
            print("This number is outside of the allotted range. Ignoring.")
total += num1
print("The total number of points for quizzes is", total)
average = total//10
print("Your average for quiz scores is", average)
total2 += num2
print("The total number of points for mini projects is", total2)
average2 = total2//10
print("Your average for mini projects is", average2)
total3 = total+total2
print("The total number of points for both is", total3)
averagefinal = ((total+total2)//20)
print("The final average for both is", averagefinal)

标签: pythonloops

解决方案


推荐阅读