![](/img/trans.png)
[英]How to add the output of a for loop inside a for loop to a list of lists? Python
[英]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.