1
當我測試一個計數器時,我發現它似乎只顯示最後一個項目通過它。例如,如果某件事情非常好,那麼它就會顯示爲「1」。然而,不管其他數據如何,其餘數據將爲0.計數器似乎並沒有正確添加
def mealrating(score, review):
for x in range(0,len(score)):
mp = 0
mg = 0
me = 0
if score[x] >= 1 and score[x] <= 3:
review.append("poor")
mp = mp + 1
if score[x] >= 4 and score[x] <= 6:
review.append("good")
mg = mg + 1
if score[x] >= 7 and score[x] <= 10:
review.append("excellent")
me = me + 1
print("The customer rated tonight's meal as:")
print('Poor:' + str(mp))
print('Good:' + str(mg))
print('Excellent:' + str(me))
print("\n")