example
โจทย์ตัวอย่างพร้อมคำอธิบาย flowchart แผนภาพ และโค้ด Python ที่รันได้
Worked problems that bring the earlier lessons together โจทย์ตัวอย่างที่นำเนื้อหาบทก่อนหน้ามารวมกัน
A lesson teaches one idea at a time; a real program needs several ideas working together. These three worked problems take a short, realistic task — analysing exam marks, measuring a triangle, smoothing a stream of readings — and solve it step by step, so you can see how variables, loops, lists, functions and decisions fit into one program.
บทเรียนสอนทีละแนวคิด แต่โปรแกรมจริงต้องใช้หลายแนวคิดทำงานร่วมกัน สามโจทย์ตัวอย่างนี้หยิบงานสั้นๆ ที่ใกล้เคียงของจริง ได้แก่ วิเคราะห์คะแนนสอบ วัดสามเหลี่ยม และทำให้ค่าที่อ่านได้เรียบขึ้น แล้วแก้ทีละขั้น เพื่อให้เห็นว่าตัวแปร ลูป list ฟังก์ชัน และการตัดสินใจประกอบกันเป็นโปรแกรมเดียวได้อย่างไร
Each example page has four parts: a problem description, a flowchart explanation, the flowchart diagram itself, and runnable Python (simulated with JavaScript, as in the lessons). A short multiple-choice exercise follows at the end.
แต่ละหน้าตัวอย่างมี 4 ส่วน: คำอธิบายโจทย์ คำอธิบาย flowchart แผนภาพ flowchart และ โค้ด Python ที่รันได้ (จำลองด้วย JavaScript เหมือนในบทเรียน) ปิดท้ายด้วยแบบฝึกหัดแบบตัวเลือกสั้นๆ
Learners who have finished the lessons on control structures and want to practise putting them together, and anyone who can follow a flowchart but is unsure how to turn it into code. It is also a good check before the data files lesson.
ผู้เรียนที่จบบท โครงสร้างควบคุม แล้วและอยากฝึกประกอบแนวคิดเข้าด้วยกัน และผู้ที่อ่าน flowchart ได้แต่ยังไม่แน่ใจว่าจะเขียนเป็นโค้ดอย่างไร ใช้ทบทวนก่อนเรียนบท ไฟล์ข้อมูล ก็ได้
while, % indexing and mathwhile การวนดัชนีด้วย % และ mathTake them in this order: each example reuses ideas from the one before it.
เรียนตามลำดับนี้ เพราะแต่ละตัวอย่างใช้แนวคิดจากตัวอย่างก่อนหน้า
Together the examples practise counting loops and while loops with a stop condition, lists and
index assignment, user-defined functions with def and return, accumulators and running
maximums, compound conditions with and, validating input before calculating, the math
module with Heron’s formula, and a circular buffer built with %.
ตัวอย่างทั้งสามฝึก ลูปนับรอบและลูป while ที่มีเงื่อนไขหยุด, list และการเขียนทับค่าด้วยดัชนี,
ฟังก์ชันที่นิยามเองด้วย def และ return, ตัวสะสมค่าและค่ามากสุดระหว่างวน,
เงื่อนไขแบบรวมด้วย and, การตรวจสอบค่าก่อนคำนวณ, โมดูล math กับสูตรของ Heron
และ circular buffer ด้วย %
When you finish you can break a small problem into steps, draw the flowchart, and turn it into working Python with functions, loops and decisions.
เมื่อจบหมวดนี้ คุณจะแตกปัญหาเล็กๆ เป็นขั้นตอน วาด flowchart และแปลงเป็นโค้ด Python ที่ทำงานได้ ด้วยฟังก์ชัน ลูป และการตัดสินใจ
โจทย์ตัวอย่างพร้อมคำอธิบาย flowchart แผนภาพ และโค้ด Python ที่รันได้