python - 我不明白这个循环,我死在里面
问题描述
编写一个程序,提示 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)
解决方案
推荐阅读
- c# - 无法从 OnGet 方法获取 id
- f# - 在 F# 中实现 List.scani 的好方法是什么?
- c - 在链表中插入节点时递归如何工作?
- javascript - 将动态标题传递给 reactjs 中的 HOC 常用函数
- vb.net - 将多个选定的 DataGridView 行写入 CSV
- regex - 如何使用 unix/linux grep/awk/sed 从文件中输出带有空格的段落
- postgresql - Docker 无法在 Centos 8 上构建 PostgreSQL 12
- .htaccess - 将 RewriteBase 从 htaccess 移动到站点 conf 不起作用
- python - NumPy - 从 3D 数组中排除所有零 2D 数组
- postgresql - 我们究竟将这个 postgresql.conf 配置文件放在 Spring Boot 应用程序中的什么位置?