此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Two kinds of number
- An integer (
int) is a whole number, like7or-3. - A float is a number with a decimal point, like
2.5. - Division with
/always gives a float, even4 / 2→2.0.
English
Add, subtract, multiply, divide
+adds,-subtracts,*multiplies,/divides.- You can use them with variables or with plain numbers.
- Spaces around operators are optional but make code easier to read.

English
print(7 + 2)
print(7 - 2)
print(7 * 2)
print(7 / 2)
English
Whole-number division, remainder, powers
//divides and rounds down to a whole number (floor division):7 // 2is3, and-7 // 2is-4.%gives the remainder (called modulo).**raises to a power:2 ** 3is 2×2×2.
English
print(7 // 2)
print(7 % 2)
print(2 ** 5)
English
Order of operations
- Python does
**first, then*///%, then+-. - This is the same order you use in maths.
- Use parentheses
(...)to change the order.
English
print(2 + 3 * 4)
print((2 + 3) * 4)
English
Common mistakes
/always gives a float (4 / 2is2.0); use//when you want a whole number.- Power is
**, not^. "3" + "4"joins text into"34"— it does not add to7.
English
Now you try
- Store each answer in the variable named in the task.
- Press Check answer to test your code.
探索
运算优先级
Python 先算 × 和 ÷,再算 + 和 −,从左到右。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
把 length 设为 8,width 设为 5。然后把它们的乘积存进变量 area。
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
把 17 颗糖分给 5 个小孩。把每人分到的数量存进 each(用 //),把剩下的数量存进 left(用 %)。
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
把 3 ** 2 + 1 的结果存进 result。再用括号把 (3 + 1) ** 2 的结果存进 grouped。
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
celsius 是 37。用公式 摄氏度 × 9 ÷ 5 + 32,把华氏温度存进 fahrenheit。
点击“运行”查看此处输出。