Running total · 累计求和
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
This one builds on a lesson you haven't finished yet. Do that lesson first: · 此任务基于您尚未完成的课程。请先完成以下课程:
Python Basics · Python 基础 · Lists (1-D arrays) · 列表(一维数组) →
English
Running total
Add up the list [5, 10, 20] one number at a time, printing the total after each step: 5, 15, 35.
Lines indented under the for run every time round the loop; a line after the loop runs only once. Here the print belongs inside the loop.
中文
累计求和
把列表 [5, 10, 20] 中的数逐个相加,每加一次就打印一次当前总和:5、15、35。
缩进在 for 下面的行每一轮都会运行;循环后面的行只运行一次。这里的 print 应该放在循环里面。
Loop over nums and keep a total. After adding each number, print the total so far: 5, then 15, then 35. · 遍历 nums 并保存一个总和。每加上一个数,就打印当前的总和:先 5,再 15,最后 35。
Click Run to see the output here. · 点击“运行”查看此处输出。