這個問題我來回答:我得到這個語法錯誤:類型錯誤:不支持的操作數類型(S)爲+:「詮釋」和「海峽」
編寫一個程序,輸入考試成績(滿分100),直到你輸入'quit'。完成輸入考試分數後,該程序將打印出所有考試分數的平均值。
提示: 要計算出平均值,您必須保持考試分數的總計和輸入的數字的計數。 嘗試使程序工作1次,然後找出退出條件並使用一段時間True:循環。
示例執行: 輸入考試的分數或類型「退出」:100 輸入考試的分數或類型「退出」:100 輸入考試的分數或類型「退出」:50 輸入考試的分數或類型「退出」:退出 分數數3.平均爲83.33
這是我的代碼:
count = 0
average = sum
while True:
num =input('Enter an exam score or type "quit":')
count = count + 1
average = sum(num)
print ('the total of exams is %d and the average is %f' % count, average)
if num == 'quit':
break
print ('this is ok for now')
您首先需要'int'(..)'num'。 –
謝謝,但這是我得到的:TypeError:'int'對象是不可迭代的 –
但是你輸入的元素一個接一個。所以你應該使用一個每次增加'num'的運行變量...... –