Add up 1 to 100 · 从 1 加到 100
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 基础 · Counting loops · 计数循环 →
English
Add up 1 to 100
Add every whole number from 1 to 100 and print the result.
This is a running total: start at 0 and add the loop variable on every pass. The starter adds 1 to 10, so you only need to change where the range stops. The young Carl Friedrich Gauss is said to have found this answer in his head by pairing 1 + 100, 2 + 99 and so on.
中文
从 1 加到 100
把 1 到 100 的每个整数加起来,并打印结果。
这是累计求和:从 0 开始,每一轮都加上循环变量。起始代码加的是 1 到 10,所以你只需要改变 range 停下的位置。据说少年高斯把 1 + 100、2 + 99 这样两两配对,在心里算出了这个答案。
Use a for loop to add up every whole number from 1 to · 到 100, then print the total once. · 用 for 循环把 1 到 100 的每个整数加起来,最后只打印一次总和。
Click Run to see the output here. · 点击“运行”查看此处输出。