ลำดับ, อินพุต &เอาต์พุต
หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
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.
สำรวจ
อินพุต → ประมวลผล → เอาต์พุต
โปรแกรมส่วนใหญ่มีรูปแบบหนึ่ง: รับอินพุต, ทำsomething, แสดงเอาต์พุต
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
พิมพ์สามบรรทัดเหล่านี้, ตามลำดับ: Ready, จากนั้น Set, แล้ว Go — บรรทัดละหนึ่งบรรทัด
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
อ่านชื่อด้วย input(), แล้วพิมพ์ Hello, ตามด้วยชื่อ แล้ว !. สำหรับอินพุต Sam, เอาต์พุตควรจะเป็น Hello, Sam!
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
อ่านจำนวนเต็มด้วย input(), แปลงด้วย int(...), แล้วพิมพ์จำนวนนั้น คูณสอง (times 2). สำหรับอินพุต 6, เอาต์พุตควรจะเป็น 12
คลิก Run เพื่อดูผลลัพธ์ที่นี่