Sequence, input & output · 顺序、输入与输出
A program runs in order
- A program is a list of steps.
- Python runs them from top to bottom, one at a time.
- This order is called sequence — the first idea in the syllabus.
程序按顺序运行
- 程序就是一串步骤。
- Python 从上到下一步一步地运行它们。
- 这种顺序叫做顺序结构(sequence)—— 考纲里的第一个概念。
print("Wake up")
print("Brush teeth")
print("Go to school")
OUTPUT becomes print()
- In the exam, OUTPUT shows something on the screen.
- In Python, that is
print(). - The text inside the quotes is printed, then a new line starts.
OUTPUT 对应 print()
- 在考试里,OUTPUT 把内容显示在屏幕上。
- 在 Python 里,这就是
print()。 - 引号里的文字会被打印出来,然后另起一行。
print("Hello, world!")
print("IGCSE Computer Science")
INPUT becomes input()
- In the exam, INPUT reads what the user types.
- In Python, that is
input(). - It always gives back a string (text), even if the user types digits.
INPUT 对应 input()
- 在考试里,INPUT 读取用户输入的内容。
- 在 Python 里,这就是
input()。 - 它总是返回一个字符串(文本),即使用户输入的是数字。
name = input()
print("Hello, " + name)
Turn input into a number
input()gives text, so"5"is not the number 5.- Wrap it with
int()to get a whole number. - Now you can do maths with it.
把输入变成数字
input()返回文本,所以"5"不是数字 5。- 用
int()把它转换成整数。 - 这样你就能用它做数学运算了。
age = int(input())
print(age + 1)
In the exam: pseudocode
- The same idea in Cambridge pseudocode uses
INPUTandOUTPUT.
在考试里:伪代码
- 同样的想法,用剑桥伪代码写就是
INPUT和OUTPUT。
OUTPUT "What is your name?"
INPUT Name
OUTPUT "Hello, ", Name
Common mistakes
- Statements run from top to bottom, in the order you write them.
input()gives back text (a string); useint(...)when you need a number.
常见错误
- 语句从上到下、按你写的顺序运行。
input()返回的是文本(字符串);需要数字时用int(...)。
Now you try
- Use
print()to show output. - Use
input()to read a line — leave the brackets empty here. - Press Check answer to test your code.
现在轮到你
- 用
print()显示输出。 - 用
input()读取一行 —— 这里括号里留空。 - 按检查答案来测试你的代码。
Input → process → output · 输入 → 处理 → 输出
Most programs follow one shape: get input, do something, show output. · 大多数程序都遵循一个模式:取得输入、做处理、显示输出。
Print these three lines, in order: Ready, then Set, then Go — one per line. · 按顺序打印这三行:先 Ready,再 Set,最后 Go —— 每行一个。
Click Run to see the output here. · 点击“运行”查看此处输出。
Read a name with input(), then print Hello, then the name then !. For the input Sam, the output should be Hello, Sam!. · 用 input() 读取一个名字,然后输出 Hello, 、名字,再加 !。当输入为 Sam 时,应输出 Hello, Sam!。
Click Run to see the output here. · 点击“运行”查看此处输出。
Read a whole number with input(), convert it with int(...), then print it doubled (times 2). For input 6, the output should be 12. · 用 input() 读取一个整数,用 int(...) 转换,然后打印它的两倍(乘以 2)。当输入为 6 时,应输出 12。
Click Run to see the output here. · 点击“运行”查看此处输出。