回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我想写一个函数,将采取任何名单,并给我回那个“总和”的答案。现在我为“recherche”做这个,但重点是为列表中的任何类型做这个。我的代码就是这样的。你知道吗</p>
<pre><code>TYPE_RECHERCHE = "recherche"
une_formation = [
[ TYPE_DIRIGEE, 7.50 ],
[ TYPE_PRESENTATION, 4.5 ],
[ TYPE_DIRIGEE, 2.00 ],
[ TYPE_CONFERENCE, 7.0 ],
[ TYPE_ATELIER, 2.25 ],
[ TYPE_GROUPE_DISCUSSION, 3.00 ],
[ TYPE_RECHERCHE, 1 ],
[ TYPE_LECTURE, 4.0 ],
[ TYPE_RECHERCHE, 4 ],
[ TYPE_RECHERCHE, 2.5 ],
[ TYPE_PRESENTATION, 3.5 ],
[ TYPE_REDACTION, 5.5 ],
[ TYPE_LECTURE, 10.0 ]
]
temps_formation_recherche = []
a = -1
while a < 12:
a = a + 1
if une_formation[a][0] == "recherche":
temps_formation_recherche.append(une_formation[a][1])
sum(temps_formation_recherche) # this will return 7.5
</code></pre>