Trình tự, đầu vào & đầu ra
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
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.

English
print("Wake up")
print("Brush teeth")
print("Go to school")
English
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.
English
print("Hello, world!")
print("IGCSE Computer Science")
English
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.
English
name = input()
print("Hello, " + name)
English
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.
English
age = int(input())
print(age + 1)
English
In the exam: pseudocode
- The same idea in Cambridge pseudocode uses
INPUTandOUTPUT.
OUTPUT "What is your name?"
INPUT Name
OUTPUT "Hello, ", Name
English
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.
English
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.
Khám phá
Input → process → output
Hầu hết các chương trình tuân theo một cấu trúc: nhập dữ liệu, thực hiện thao tác, hiển thị kết quả.
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
In ba dòng này, theo thứ tự: Ready, sau đó Set, rồi Go — mỗi dòng một lần.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Đọc tên bằng input(), sau đó in Hello, , rồi tên, rồi !. Với đầu vào Sam, kết quả phải là Hello, Sam!.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Đọc số nguyên bằng input(), chuyển đổi bằng int(...), sau đó in ra số đó bằng hai lần (nhân với 2). Với đầu vào 6, kết quả phải là 12.
Nhấn Chạy để xem kết quả ở đây.