此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
程序按顺序运行
- 程序就是一串步骤。
- Python 从上到下一步一步地运行它们。
- 这种顺序叫做顺序结构(sequence)—— 考纲里的第一个概念。
English
print("Wake up")
print("Brush teeth")
print("Go to school")
OUTPUT 对应 print()
- 在考试里,OUTPUT 把内容显示在屏幕上。
- 在 Python 里,这就是
print()。 - 引号里的文字会被打印出来,然后另起一行。
English
print("Hello, world!")
print("IGCSE Computer Science")
INPUT 对应 input()
- 在考试里,INPUT 读取用户输入的内容。
- 在 Python 里,这就是
input()。 - 它总是返回一个字符串(文本),即使用户输入的是数字。
English
name = input()
print("Hello, " + name)
把输入变成数字
input()返回文本,所以"5"不是数字 5。- 用
int()把它转换成整数。 - 这样你就能用它做数学运算了。
English
age = int(input())
print(age + 1)
在考试里:伪代码
- 同样的想法,用剑桥伪代码写就是
INPUT和OUTPUT。
OUTPUT "What is your name?"
INPUT Name
OUTPUT "Hello, ", Name
常见错误
- 语句从上到下、按你写的顺序运行。
input()返回的是文本(字符串);需要数字时用int(...)。
现在轮到你
- 用
print()显示输出。 - 用
input()读取一行 —— 这里括号里留空。 - 按检查答案来测试你的代码。
探索
Input → process → output
Most programs follow one shape: get input, do something, show output.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Print these three lines, in order: Ready, then Set, then Go — one per line.
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Read a name with input(), then print Hello, then the name then !. For the input Sam, the output should be Hello, Sam!.
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Read a whole number with input(), convert it with int(...), then print it doubled (times 2). For input 6, the output should be 12.
点击“运行”查看此处输出。