我想从列表的app_data_set列表中计算所有评级的总和,并将其存储在rating_sum中
我的代码只将“row_1”评级加5次,并将其存储在rating_sum中,而不是将每行的评级相加
row_1 = ['Facebook', 0.0, '$', 2974676, 3.5]
row_2 = ['Instagram', 0.0, '$', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, '$', 2130805, 4.5]
row_4 = ['Temple Run', 0.0, '$', 1724546, 4.5]
row_5 = ['Pandora - Music & Radio', 0.0, '$', 1126879, 4.0]
app_data_set = [row_1, row_2, row_3, row_4, row_5 ]
rating_sum = 0
for rating in app_data_set:
rating = app_data_set[0][4]
rating_sum = rating_sum + app_data_set[0][4]
print(rating_sum)
我预计产出为:
3.5
8.0
12.5
16.5
20.5
实际产出为:
3.5
7.0
10.5
14.0
17.5
请尝试改用此循环:
其中:
(注意,你的输出是错误的,我的应该是正确的,请计算一下)
相关问题 更多 >
编程相关推荐