INPUT and data types
Cambridge Pseudocode Lesson 3 1:42 English narration · English + 中文 subtitles burned in
Chapters
Transcript
INPUT reads one line that the user types and stores it in the variable you name.
INPUT 读入用户输入的一行,并把它存进你指定的那个变量里。
That is the whole statement — no prompt, no brackets.
整条语句就这些——没有提示语,没有括号。
Pair it with an OUTPUT and you have a program that talks back: read a name, then greet them by name.
把它和一个 OUTPUT 配在一起,你就有了一个会回话的程序: 读入一个名字,然后用名字跟他打招呼。
Every task in this lesson reads exactly one value this way.
这一课的每一道题都是用这种方式读入恰好一个值。
Five type names carry marks, so learn them with an example each.
有五个类型名是要给分的,所以每一个都配一个例子来记。
INTEGER is a whole number.
INTEGER 是整数。
REAL is a number with a decimal point.
REAL 是带小数点的数。
CHAR is exactly one character, and it takes single quotes.
CHAR 恰好是一个字符,而且用单引号。
STRING is any text at all, in double quotes.
STRING 是任意的文字,用双引号。
And BOOLEAN holds only TRUE or FALSE, written in capitals.
而 BOOLEAN 只装 TRUE 或 FALSE,写成大写。
A-Level adds a sixth, DATE.
A-Level 还多一个 DATE。
And here is why the declaration is not optional.
而这就是为什么那个声明不是可有可无的。
Whatever the user types arrives as text, so adding one to it fails — the program looks right and does not run.
用户输入的东西一律是以文本的形式到达的, 所以给它加 1 会失败——程序看起来没问题,但跑不起来。
Declare it as an INTEGER first and the same input becomes a number, so the arithmetic works and seventeen comes out.
先把它声明为 INTEGER,同样的输入就成了一个数字, 于是算术能算,17 就出来了。
The user typed sixteen either way; the DECLARE is what decided how to read it.
两种情况下用户输入的都是 16; 是那句 DECLARE 决定了怎么去读它。
Four things to take with you.
带走四点。
One: INPUT reads one typed line into a variable.
第一:INPUT 把用户输入的一行读进一个变量。
Two: DECLARE the type before you do arithmetic on it.
第二:在对它做算术之前先声明类型。
Three: the five names are INTEGER, REAL, CHAR, STRING, BOOLEAN.
第三:那五个名字是 INTEGER、REAL、CHAR、STRING、BOOLEAN。
Four: CHAR holds one character in single quotes.
第四:CHAR 用单引号装一个字符。
Now do the three tasks.
现在去做那三道题。