Skip to content

Sequence, input, output

Python for IGCSE CS Lesson 1 2:04 English narration · English + 中文 subtitles burned in

space play · ←/→ 5s · j/l 10s · f fullscreen · ,/. speed

Chapters

Transcript
The syllabus starts with a word that sounds too simple to need naming: sequence. 考纲的第一个词,简单到好像不值得起名字:顺序。
A program is a list of steps, and Python runs them from the top down, one at a time. 程序就是一串步骤,Python 从上往下、一次一条地执行它们。
Three prints, and the three lines appear in that order. 三个 print,三行文字就按那个顺序出现。
Swap two of them and the output swaps with them — order is the program, not a detail of how it is laid out. 把其中两行调换,输出也跟着换—— 顺序就是程序本身,不是排版上的细节。
Now the thing that makes this course different from an ordinary Python course. 现在说说这门课和普通 Python 课的区别。
Your exam paper is written in Cambridge pseudocode, not in Python. 你的考卷是用剑桥伪代码写的,不是 Python。
So every lesson here shows both, line for line: OUTPUT is print, INPUT is input, and the arrow that assigns a value is the equals sign. 所以这里每一课都会把两者并排放出来,一行对一行: OUTPUT 就是 print,INPUT 就是 input, 而那个赋值用的箭头,就是等号。
Learn to read across between the two, and the exam stops looking like a different language from everything you type. 学会在两者之间横着读, 考卷就不再像是一门和你平时敲的东西不同的语言了。
One detail catches everybody once. 有一个细节,每个人都会栽一次。
Input always hands back text, even when the user typed digits. input 交回来的永远是文本,哪怕用户输入的是数字。
So adding one to it is an error, not a sum. 所以给它加 1,得到的是一个错误,不是一个和。
Wrap it in int and the text becomes a whole number, and the arithmetic works. 用 int 把它包起来,文本就变成了整数,运算就成立了。
Remember what is really arriving: the characters "five", not the number five. 记住真正到达的是什么:是字符 "5",不是数字 5。
Put the three ideas together and you have the lesson's third task. 把这三个概念合起来,就是这一课的第三道题。
The user types six. 用户输入 6。
Input reads it as text, int turns it into the number, and print shows it times two — so six comes out as twelve. input 把它读成文本,int 把它变成数字, print 把它乘以 2 显示出来——于是 6 变成了 12。
Input, process, output: that is the shape of almost every program the exam will ever ask you for. 输入、处理、输出: 考试会让你写的几乎每一个程序,都是这个形状。
Four things to take with you. 带走四点。
One: sequence means the lines run top to bottom. 第一:顺序,指的是代码行从上往下执行。
Two: the exam's OUTPUT is Python's print. 第二:考卷上的 OUTPUT 就是 Python 的 print。
Three: the exam's INPUT is Python's input. 第三:考卷上的 INPUT 就是 Python 的 input。
Four: input gives text, so wrap it in int when you need a number. 第四:input 给的是文本,需要数字时要用 int 包起来。
Now do the three tasks. 现在去做那三道题。

Log in or create account

IGCSE, A-Level & AP