繁体   English   中英

如何在 for 循环中添加 readline 的 output

[英]How to add the output of a readline inside a for loop

我正在尝试编写一个循环,该循环将为用户定义的某些测试找到测试平均值。 我需要添加循环中运行的所有 readlines 的输出/输入(您在控制台中键入的数字)。

我过去对这个项目做了一个变体,你可以输入一定数量的测试分数,但我没有在循环中添加 readlines 的经验

test_no = int(input("How Many Tests Did You Take: "))
for x in range (1, test_no+1):
    t_score = int(input("The Score on Test %s Was: " % x)) 
average = t_score/test_no
print (average)

我期待 output 在循环内添加了 readline function 的所有输出,并且十除以循环运行的次数

就像@ForceBrue 评论的那样,您没有添加分数,而是覆盖。 我想这就是你想要实现的目标:

test_no = int(input("How Many Tests Did You Take: "))
t_score = 0
for x in range (1, test_no+1):
    t_score += int(input("The Score on Test %s Was: " % x)) 
average = t_score/test_no
print (average)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM