N = []
stop = 1
while(stop != "0"):
number = input("Give a mark: ")
stop = raw_input("type 0 if you want to stop the program.")
N.append(number)
print (float(sum(N)))/(len(N))
這是我的代碼。我想知道我給該計劃的平均分數。現在,我想這會工作,但它引發以下錯誤:如何獲得python列表中數字的總和?
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
它使用float和所有其他類型的數字相同,我怎麼sopposed獲得這些商標的總和,如果我不能使用總和()?
你的問題是太多的括號。只需使用print 1.0 * sum(N)/ len(N)'' – randomusername
'N = [1,2,3]; print(float(sum(N)))/(len(N))'工作正常,不能重現。 –
函數輸入的輸出是一個字符串,您將其存儲到列表中。首先將其轉換爲int,然後繼續。 – RvdK