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() - มันจะคืนค่าเป็น string (ข้อความ) เสมอ แม้ผู้ใช้จะพิมพ์ตัวเลขก็ตาม
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.
ในการสอบ: Pseudocode
- แนวคิดเดียวกันใน Cambridge pseudocode ใช้
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()คืนค่าเป็นข้อความ (string); ใช้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()เพื่ออ่านบรรทัด — ทิ้งวงเล็บว่างเปล่าที่นี่ - กด Check answer เพื่อทดสอบโค้ดของคุณ
Input → process → output · อินพุต → ประมวลผล → เอาต์พุต
Most programs follow one shape: get input, do something, show output. · โปรแกรมส่วนใหญ่มีรูปแบบหนึ่ง: รับอินพุต, ทำsomething, แสดงเอาต์พุต
Print these three lines, in order: Ready, then Set, then Go — one per line. · พิมพ์สามบรรทัดเหล่านี้, ตามลำดับ: Ready, จากนั้น Set, แล้ว Go — บรรทัดละหนึ่งบรรทัด
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
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. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
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(...), แล้วพิมพ์จำนวนนั้น คูณสอง (times 2). สำหรับอินพุต 6, เอาต์พุตควรจะเป็น 12
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่