Flowchart Basic — Planning Before You Code Flowchart พื้นฐาน — วางแผนก่อนเขียนโค้ด

Learn why flowcharts matter, the eight ANSI/ISO symbols, and how each one maps to program logic. เรียนรู้ความสำคัญของ flowchart สัญลักษณ์ ANSI/ISO 8 ชนิด และการเชื่อมแต่ละสัญลักษณ์กับ logic ของโปรแกรม

Flowchart Basic Flowchart พื้นฐาน
1 Why draw a flowchart first? ทำไมควรวาด flowchart ก่อนเขียนโค้ด?

A flowchart is a visual diagram of the steps in a program. Long lists of instructions are hard to follow; a diagram shows the order at a glance. Drawing one before you write Python helps you plan the control flow — the sequence of actions, decisions, and loops.

Flowchart คือแผนภาพขั้นตอนของโปรแกรม รายการคำสั่งยาว ๆ อ่านยาก แต่แผนภาพแสดงลำดับได้ทันที การวาด flowchart ก่อน เขียน Python ช่วยวางแผน control flow คือลำดับการทำงาน การตัดสินใจ และการวนซ้ำ

A good flowchart maps cleanly to structured programming: sequence (do steps in order), selection (choose a path with if/else), and iteration (repeat with loops). Each block has a clear entry and exit, so the logic is easier to check and explain to others.

Flowchart ที่ดีแปลเป็น structured programming ได้ชัดเจน: sequence (ทำตามลำดับ), selection (เลือกเส้นทางด้วย if/else) และ iteration (วนซ้ำด้วย loop) แต่ละบล็อกมีจุดเข้าและจุดออกชัด จึงตรวจ logic และอธิบายให้ผู้อื่นเข้าใจได้ง่าย

Did you know? รู้หรือไม่? Frank and Lillian Gilbreth introduced flow process charts in 1921 to study efficient work flows — long before modern programming. Frank และ Lillian Gilbreth นำเสนอ flow process chart ในปี 1921 เพื่อศึกษาการทำงานอย่างมีประสิทธิภาพ — ก่อนยุคการเขียนโปรแกรมสมัยใหม่นาน
2 Standard symbols (ANSI / ISO) สัญลักษณ์มาตรฐาน (ANSI / ISO)
Table 1 — Eight common flowchart symbols. ตารางที่ 1 — สัญลักษณ์ flowchart ที่ใช้บ่อย 8 ชนิด
Shapeรูปทรง Nameชื่อ Descriptionคำอธิบาย
TerminatorTerminator Start or stop of the program (or sub-chart).จุดเริ่มหรือจบของโปรแกรม (หรือ sub-chart)
Data (Input / Output)Data (Input / Output) Read data in or write results out.รับข้อมูลเข้าหรือส่งผลลัพธ์ออก
DecisionDecision A yes/no or true/false test; two exit paths.ทดสอบ Yes/No หรือ True/False มีสองเส้นทางออก
ProcessProcess A calculation or action that changes data.การคำนวณหรือการกระทำที่เปลี่ยนข้อมูล
Sub-processSub-process Call another module or function defined elsewhere.เรียกโมดูลหรือฟังก์ชันที่นิยามไว้ที่อื่น
On-page connectorOn-page connector Jump to a matching circle on the same page (labelled A, B, …).กระโดดไปวงกลมคู่ในหน้าเดียวกัน (ใส่ label A, B, …)
Off-page connectorOff-page connector Continue on another page (pentagon points to the exit).ต่อในหน้าอื่น (รูปห้าเหลี่ยมชี้ทิศทางออก)
FlowlineFlowline Arrow showing the order of execution between symbols.ลูกศรแสดงลำดับการทำงานระหว่างสัญลักษณ์
3 Terminator Terminator

The terminator is a rounded rectangle (pill) labelled START or STOP. It marks where control enters and leaves a chart.

Terminator เป็นรูปสี่เหลี่ยมมุมโค้ง (pill) ที่เขียนว่า START หรือ STOP ใช้ทำเครื่องหมายจุดที่การทำงานเข้าและออกจากแผนภาพ

How it works: every main flowchart has exactly one START and one STOP. A separate sub-chart for a function also opens and closes with terminators — the sub-chart for find_total() begins at its own START and ends with Return, handing control back to the caller.

การทำงาน: ทุก flowchart หลักมี START หนึ่งจุดและ STOP หนึ่งจุด sub-chart ของฟังก์ชันก็เปิดและปิดด้วย terminator เช่นกัน — sub-chart ของ find_total() เริ่มที่ START ของตัวเอง และจบด้วย Return เพื่อส่งการทำงานกลับไปยังผู้เรียก

Main program START STOP Sub-process find_total() Return
One START/STOP per chart; a sub-chart returns to its caller. หนึ่ง START/STOP ต่อหนึ่งแผนภาพ; sub-chart ส่งกลับไปยังผู้เรียก
[demo]
[output]
240
4 Data (Input / Output) Data (Input / Output)

The parallelogram marks input or output. Input reads a value from outside the program (keyboard, file, sensor). Output sends a result back (screen, printer, file). In Python these become input() and print().

สี่เหลี่ยมด้านขนาน (parallelogram) ใช้กับ input หรือ output Input อ่านค่าจากภายนอกโปรแกรม (คีย์บอร์ด ไฟล์ เซนเซอร์) Output ส่งผลลัพธ์ออก (หน้าจอ เครื่องพิมพ์ ไฟล์) ใน Python มักเป็น input() และ print()

How it works: the flow reads a value in through an Input parallelogram, then later writes the result out through an Output parallelogram — the shape is the same, only the direction of the data changes.

การทำงาน: การไหลรับค่าเข้ามาผ่าน parallelogram แบบ Input แล้วจึงส่งผลลัพธ์ออกผ่าน parallelogram แบบ Output — รูปทรงเหมือนกัน ต่างกันแค่ทิศทางของข้อมูล

START Input Output STOP
Read a value, then display a result. อ่านค่า แล้วแสดงผลลัพธ์
[demo]
[output]
25
77.0
5 Decision Decision

The diamond holds a condition with two labelled exits, usually Yes and No (or True / False). Only one path is taken.

รูปสี่เหลี่ยมข้าวหลามตัด (diamond) ใส่เงื่อนไขที่มีทางออกสองทาง มักเป็น Yes และ No (หรือ True / False) เลือกได้เพียงเส้นทางเดียว

How it works: read a number, test number % 2 == 0. Yes → output “even”; No → output “odd”. Both branches rejoin before STOP.

การทำงาน: อ่านค่า number แล้วทดสอบ number % 2 == 0 ถ้า Yes → แสดง “even” ถ้า No → แสดง “odd” ทั้งสองเส้นทางมารวมกันก่อนถึง STOP

START read number number % 2 == 0 Yes No print "even" print "odd" A STOP
The diamond splits the flow; the circle merges it again. diamond แยกเส้นทาง แล้ววงกลมนำมารวมกันอีกครั้ง
[demo]
[output]
odd
6 Process Process

A rectangle is a process step: assign a value, compute a formula, or update a variable. No branching — execution continues straight down to the next symbol.

สี่เหลี่ยม (rectangle) คือขั้นตอน process: กำหนดค่า คำนวณสูตร หรืออัปเดตตัวแปร ไม่มีการแตกแขนง — ทำงานต่อลงสัญลักษณ์ถัดไปทันที

How it works: read Celsius C, run one process block F = (float(C) * 1.8) + 32, then output F.

การทำงาน: อ่านค่าองศาเซลเซียส C ทำ process หนึ่งบล็อก F = (float(C) * 1.8) + 32 แล้วแสดงผล F

START read C F = (float(C)*1.8) + 32 output F STOP
Input, one process block, output — a straight line. รับ input → process หนึ่งบล็อก → output — เป็นเส้นตรง
[demo]
[output]
212.0
7 Sub-process Sub-process

A rectangle with double side-bars is a predefined process: “run the steps in another chart or function.” The main chart stays short; the detail lives in a sub-chart.

สี่เหลี่ยมที่มีขีดสองข้าง คือ predefined process: “รันขั้นตอนในแผนภาพหรือฟังก์ชันอื่น” แผนหลักจึงสั้น ส่วนรายละเอียดอยู่ใน sub-chart

How it works: the main chart reads a list of scores, then calls total = find_total(scores) as one predefined-process box and displays the result. The loop that actually adds the numbers is drawn separately (see card 10).

การทำงาน: แผนหลักอ่านลิสต์คะแนน แล้วเรียก total = find_total(scores) เป็นกล่อง predefined process หนึ่งกล่อง และแสดงผลลัพธ์ ส่วน loop ที่บวกตัวเลขจริง ๆ วาดแยกไว้ต่างหาก (ดู card 10)

START read scores total = find_total(scores) show total STOP
One box hides a whole sub-chart. กล่องเดียวซ่อน sub-chart ทั้งแผน
[demo]
[output]
240
8 On-page connector On-page connector

When two paths would need long or crossing arrows on one page, a pair of labelled circles replaces the line. Both circles share the same letter (A, B, …).

เมื่อสองเส้นทางต้องใช้ลูกศรยาวหรือไขว้กันในหน้าเดียว ใช้วงกลมคู่ที่มี label แทนเส้น วงกลมทั้งคู่ใช้ตัวอักษรเดียวกัน (A, B, …)

How it works: here both branches of a decision must reach STOP. Instead of drawing two arrows that cross, each branch ends at a circle A; a single circle A picks the flow back up and continues to STOP.

การทำงาน: ในตัวอย่างนี้ทั้งสองแขนงของ decision ต้องไปถึง STOP แทนที่จะวาดลูกศรสองเส้นไขว้กัน ให้แต่ละแขนงจบที่วงกลม A แล้ววงกลม A อีกจุดรับการไหลต่อไปยัง STOP

n > 0 ? Yes No print "+" print "-" A STOP
Matching circles "A" join the two branches without crossing lines. วงกลม "A" คู่กันเชื่อมสองแขนงโดยไม่ต้องมีเส้นไขว้
9 Off-page connector Off-page connector

An off-page connector is a pentagon with a page number or label. It shows that the flow continues on another sheet; the matching pentagon on the next page is the entry point.

Off-page connector เป็นรูปห้าเหลี่ยมพร้อมเลขหน้าหรือ label แสดงว่าการไหลต่อในหน้าถัดไป pentagon คู่ในหน้านั้นคือจุดเข้า

How it works: a large chart is split across pages. Page 1 ends with pentagon 2; page 2 begins with pentagon 2 and carries on to STOP. The practice programs below (cards 12–15) use exactly this to break their charts into two pages.

การทำงาน: แผนภาพใหญ่ถูกแบ่งเป็นหลายหน้า หน้า 1 จบด้วย pentagon 2 หน้า 2 เริ่มด้วย pentagon 2 แล้วทำงานต่อไปจนถึง STOP โปรแกรมฝึกด้านล่าง (card 12–15) ใช้วิธีนี้แบ่งแผนภาพออกเป็นสองหน้าพอดี

Page 1 START read data 2 Page 2 2 process data STOP
Pentagon "2" exits page 1 and re-enters on page 2. ห้าเหลี่ยม "2" ออกจากหน้า 1 แล้วเข้าใหม่ในหน้า 2
10 for loop for loop

A for loop repeats a block once for each item in a list. In a flowchart it is a decision that checks a counter (i < len(scores)) with a loop-back arrow: while the test is Yes, run the body and return to the test; when it is No, leave the loop.

for loop ทำบล็อกซ้ำหนึ่งครั้งต่อหนึ่งสมาชิกในลิสต์ ใน flowchart คือ decision ที่ตรวจตัวนับ (i < len(scores)) พร้อมลูกศร ย้อนกลับ: ตราบใดที่ผลเป็น Yes ให้ทำ body แล้วกลับไปตรวจใหม่ เมื่อเป็น No จึงออกจาก loop

How it works: find_total(scores) starts with total = 0 and i = 0. Each pass adds scores[i] to total and increases i. When i reaches the list length, it returns total.

การทำงาน: find_total(scores) เริ่มด้วย total = 0 และ i = 0 แต่ละรอบบวก scores[i] เข้ากับ total แล้วเพิ่ม i เมื่อ i ถึงความยาวลิสต์ก็คืนค่า total

find_total(scores) total = 0 i = 0 i < len(scores) Yes score = scores[i] total = total + score i += 1 No return total
The counter test plus a loop-back arrow is a for loop. การตรวจตัวนับพร้อมลูกศรย้อนกลับ คือ for loop
[demo]
[output]
418
11 while loop while loop

A while loop repeats as long as a condition is true — the number of passes is not known in advance. A common pattern is a boolean flag that the loop body switches off once the work is done.

while loop ทำซ้ำ ตราบใดที่เงื่อนไขเป็นจริง — ไม่รู้จำนวนรอบล่วงหน้า รูปแบบที่พบบ่อยคือใช้ flag แบบ boolean ที่ body ของ loop ปิดมันเองเมื่อทำงานเสร็จ

How it works: the flag While_loop_status starts True. Each pass the decision While_loop_status == True? is checked — No goes straight to Stop. On Yes, read an entry, then test Entry.isdigit()?. If No, print “Please type the numbers.” and loop back to the flag test. If Yes, print the entry, set While_loop_status = False, and loop back — now the flag test fails and the program stops.

การทำงาน: flag While_loop_status เริ่มเป็น True ทุกรอบจะตรวจ decision While_loop_status == True? — ถ้า No ไปที่ Stop ทันที ถ้า Yes ให้อ่าน entry แล้วทดสอบ Entry.isdigit()? ถ้า No แสดง “Please type the numbers.” แล้วย้อนกลับไปตรวจ flag ถ้า Yes แสดงค่า entry ตั้ง While_loop_status = False แล้วย้อนกลับ — คราวนี้เงื่อนไข flag เป็นเท็จ โปรแกรมจึงหยุด

START While_loop_status = True While_loop_status == True ? No Stop Yes Input: entry Entry.isdigit() ? No Output: Print( "Please type the numbers.") Yes Output: Print(Entry) While_loop_status = False
A boolean flag drives the loop; the body sets it False to exit. flag แบบ boolean ควบคุม loop; body ตั้งเป็น False เพื่อออก
[demo]
[output]
Please type the numbers.
Please type the numbers.
42

Practice: Flowchart and Runnable Python ฝึกหัด: Flowchart และ Python ที่รันได้

12 Example program 1 — Test Score Analyzer ตัวอย่างโปรแกรม 1 — วิเคราะห์คะแนนสอบ

Read 5 test scores into a list, then report the total, average, highest, and lowest using four user-defined functions — find_total, find_average, find_highest, find_lowest. Each function is a small sub-chart of its own.

รับคะแนนสอบ 5 ค่าเข้าลิสต์ แล้วรายงาน ผลรวม ค่าเฉลี่ย ค่ามากสุด และ ค่าน้อยสุด โดยใช้ฟังก์ชันที่นิยามเอง 4 ตัว — find_total, find_average, find_highest, find_lowest แต่ละฟังก์ชันมี sub-chart ของตัวเอง

Main program โปรแกรมหลัก

How the main flow works: page 1 is a counting loop — while i < 5, ask for a score and store it, then add 1 to i. When the loop ends it passes through connector 2. Page 2 calls the four functions in turn as predefined processes and displays every result.

การทำงานของ flow หลัก: หน้า 1 เป็น loop นับรอบ — ตราบใดที่ i < 5 ให้ถามคะแนนและเก็บไว้ แล้วบวก 1 ที่ i เมื่อ loop จบก็ผ่าน connector 2 หน้า 2 เรียกฟังก์ชันทั้งสี่ทีละตัวเป็น predefined process แล้วแสดงผลทุกค่า

Page 1 START scores = [] i = 0 i < 5 Yes ask & store a score i += 1 No 2
Page 2 2 total = find_total(scores) average = find_average(scores) highest = find_highest(scores) lowest = find_lowest(scores) display total, average, highest, lowest STOP
[main]
[output]
418
83.6
90
75

find_total(scores)

Adds every score with a counter loop: start total = 0, then for each index add scores[i] and step i on. Return total when the counter reaches the list length.

บวกทุกคะแนนด้วย loop นับรอบ: เริ่ม total = 0 แล้วแต่ละดัชนีบวก scores[i] และเดิน i ต่อ คืน total เมื่อตัวนับถึงความยาวลิสต์

find_total(scores) total = 0 i = 0 i < len(scores) Yes score = scores[i] total = total + score i += 1 No return total
A counter test with a loop-back arrow — a for loop. การตรวจตัวนับพร้อมลูกศรย้อนกลับ — คือ for loop
[demo]
[output]
418

find_average(scores)

Divides the total by how many scores there are. It has no loop of its own — it calls find_total and then one division.

หารผลรวมด้วยจำนวนคะแนน ไม่มี loop ของตัวเอง — เรียก find_total แล้วหารหนึ่งครั้ง

The loop inside find_total(scores) is shown above — jump to it. loop ภายใน find_total(scores) แสดงไว้ด้านบน — กดเพื่อเลื่อนไปดู

find_average(scores) mean = find_total(scores) / len(scores) return mean
[demo]
[output]
83.6

find_highest(scores)

Starts highest at float('-inf') so the first real score always beats it, then keeps the biggest score seen so far. An inner decision score > highest decides whether to replace it.

ตั้ง highest เป็น float('-inf') เพื่อให้คะแนนจริงตัวแรกมากกว่าเสมอ แล้วเก็บคะแนนที่มากที่สุดที่เจอ decision ภายใน score > highest ตัดสินว่าจะแทนค่าไหม

find_highest(scores) highest = float('-inf') i = 0 i < len(scores) No return highest Yes score = scores[i] score > highest Yes highest = score i += 1 No
[demo]
[output]
90

find_lowest(scores)

The mirror of find_highest: start at float('inf') and keep the smallest score, testing score < lowest.

กลับด้านของ find_highest: เริ่มที่ float('inf') และเก็บคะแนนที่น้อยที่สุด โดยทดสอบ score < lowest

find_lowest(scores) lowest = float('inf') i = 0 i < len(scores) No return lowest Yes score = scores[i] score < lowest Yes lowest = score i += 1 No
[demo]
[output]
75
13 Example program 2 — Number quiz ตัวอย่างโปรแกรม 2 — ทายตัวเลขสุ่ม

Generate 5 random integers from 1–20, show them, and ask the user for the largest and smallest. find_largest(numbers) and find_smallest(numbers) compute the real answers; the program then checks each guess in turn.

สุ่มจำนวนเต็ม 5 ตัวจาก 1–20 แสดงให้ดู แล้วถามผู้ใช้ว่าตัวมากที่สุดและน้อยที่สุดคืออะไร find_largest(numbers) และ find_smallest(numbers) หาคำตอบจริง แล้วโปรแกรมตรวจคำตอบทีละข้อ

Main program โปรแกรมหลัก

How the main flow works: page 1 builds the random list, displays it, and reads the two guesses, then hands over through connector 2. Page 2 computes Largest_number and Smallest_number, then checks the largest guess and the smallest guess one after the other — each check prints “Correct!” or “Incorrect!” before both paths merge and stop.

การทำงานของ flow หลัก: หน้า 1 สร้างลิสต์สุ่ม แสดงผล และอ่านคำตอบสองข้อ แล้วส่งต่อผ่าน connector 2 หน้า 2 คำนวณ Largest_number และ Smallest_number แล้วตรวจคำตอบตัวมากและตัวน้อย ทีละข้อต่อกัน — แต่ละข้อแสดง “Correct!” หรือ “Incorrect!” ก่อนที่ทั้งสองเส้นทางจะมารวมกันแล้วหยุด

Page 1 START numbers = random.sample(range(1,21), 5) display numbers input: largest guess input: smallest guess 2
Page 2 2 Largest_number = find_largest(numbers) Smallest_number = find_smallest(numbers) largest guess == Largest_number ? Yes Correct! No Incorrect! smallest guess == Smallest_number ? Yes Correct! No Incorrect! stop
[main]
[output]
numbers: [1, 3, 20, 15, 13]
largest: Correct!
smallest: Incorrect! it was 1

find_largest(numbers)

Starts largest at float('-inf') and keeps the biggest number seen, testing number > largest each pass.

ตั้ง largest เป็น float('-inf') และเก็บตัวเลขที่มากที่สุดที่เจอ โดยทดสอบ number > largest ทุกรอบ

find_largest(numbers) largest = float('-inf') i = 0 i < len(numbers) No return largest Yes number = numbers[i] number > largest Yes largest = number i += 1 No
[demo]
[output]
20

find_smallest(numbers)

The mirror of find_largest: start at float('inf') and keep the smallest number, testing number < smallest.

กลับด้านของ find_largest: เริ่มที่ float('inf') และเก็บตัวเลขที่น้อยที่สุด โดยทดสอบ number < smallest

find_smallest(numbers) smallest = float('inf') i = 0 i < len(numbers) No return smallest Yes number = numbers[i] number < smallest Yes smallest = number i += 1 No
[demo]
[output]
1
14 Example program 3 — Shopping receipt ตัวอย่างโปรแกรม 3 — ใบเสร็จซื้อของ

Ask for the prices of 6 items, store them in a list, then report the total cost, the average item price, and the most expensive item using calculate_total, calculate_average, and find_most_expensive.

ถามราคาสินค้า 6 ชิ้น เก็บในลิสต์ แล้วรายงานราคารวม ราคาเฉลี่ยต่อชิ้น และชิ้นที่แพงที่สุด โดยใช้ calculate_total, calculate_average และ find_most_expensive

Main program โปรแกรมหลัก

How the main flow works: page 1 is a counting loop — while i < 6, ask for a price, append it, add 1 to i. When the loop ends it passes through connector 2. Page 2 calls the three functions and displays the results.

การทำงานของ flow หลัก: หน้า 1 เป็น loop นับรอบ — ตราบใดที่ i < 6 ให้ถามราคา เพิ่มเข้าลิสต์ แล้วบวก 1 ที่ i เมื่อ loop จบก็ผ่าน connector 2 หน้า 2 เรียกฟังก์ชันสามตัวและแสดงผล

Page 1 START prices = [] i = 0 i < 6 Yes ask a price, append to prices i += 1 No 2
Page 2 2 total = calculate_total(prices) average = calculate_average(prices) highest = find_most_expensive(prices) display total, average, highest STOP
[main]
[output]
63.0
10.5
15.75

User-defined functions — already drawn ฟังก์ชันที่นิยามเอง — วาดไว้แล้ว

All three helpers are the same shapes you saw in Example program 1 — only the list name changes. Jump to each flowchart:

ตัวช่วยทั้งสามใช้รูปเดียวกับที่เห็นใน ตัวอย่างโปรแกรม 1 — เปลี่ยนแค่ชื่อลิสต์ กดเพื่อไปดูแต่ละ flowchart:

calculate_total(prices) — the counter loop of find_total(scores). calculate_total(prices) — loop นับรอบของ find_total(scores)

calculate_average(prices) — same two steps as find_average(scores). calculate_average(prices) — สองขั้นตอนเดียวกับ find_average(scores)

find_most_expensive(prices) — the max scan of find_highest(scores). find_most_expensive(prices) — การไล่หาค่ามากของ find_highest(scores)

15 Example program 4 — Password checker ตัวอย่างโปรแกรม 4 — ตรวจรหัสผ่าน

Read a password and set three flags with has_uppercase, has_lowercase, and has_digit. The password is strong only if it is longer than 8 characters and all three flags are true.

อ่านรหัสผ่านแล้วตั้งค่า flag สามตัวด้วย has_uppercase, has_lowercase และ has_digit รหัสผ่านจะ strong ก็ต่อเมื่อยาวเกิน 8 ตัวอักษร และ flag ทั้งสามเป็นจริง

Main program โปรแกรมหลัก

How the main flow works: page 1 reads the password and runs the three checks as predefined processes, then passes through connector 2. Page 2 is one combined decision — if the length test and all three flags hold, print “Strong password”; otherwise print “Weak password”. Both outputs merge at one connector, then Stop.

การทำงานของ flow หลัก: หน้า 1 อ่านรหัสผ่านและทำการตรวจสามอย่างเป็น predefined process แล้วผ่าน connector 2 หน้า 2 เป็น decision รวมหนึ่งครั้ง — ถ้าเงื่อนไขความยาวและ flag ทั้งสามเป็นจริง แสดง “Strong password” ไม่งั้นแสดง “Weak password” ทั้งสองผลลัพธ์มารวมกันที่ connector เดียวแล้วจึง Stop

Page 1 START input password status_upper = has_uppercase(password) status_lower = has_lowercase(password) status_digit = has_digit(password) 2
Page 2 2 len(password) > 8 & status_upper & status_lower & status_digit Yes "Strong password" No "Weak password" Stop
[main]
[output]
Strong password

has_uppercase(password)

Walk the characters; the moment one passes char.isupper() the function returns True. If the loop finishes with no hit, it returns False.

ไล่ดูตัวอักษรทีละตัว ทันทีที่ตัวใดผ่าน char.isupper() ฟังก์ชันจะคืน True ถ้า loop จบโดยไม่เจอ จะคืน False

has_uppercase(password) i < len(password) No return False Yes char = password[i] char.isupper() No Yes return True
[demo]
[output]
True

has_lowercase(password) / has_digit(password)

Exactly the shape of has_uppercase(password) — swap char.isupper() for char.islower() or char.isdigit(). รูปเดียวกับ has_uppercase(password) — เปลี่ยน char.isupper() เป็น char.islower() หรือ char.isdigit()

[demo]
[output]
True
[demo]
[output]
True

References อ้างอิง

End-of-lesson quizแบบฝึกหัดท้ายบท

ตอบแล้ว 0 / 10

ข้อ 1

1 / 10

Why draw a flowchart before writing Python code?ทำไมควรวาด flowchart ก่อนเขียนโค้ด Python?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (A) To plan control flow and check logic before codingเพื่อวางแผน control flow และตรวจ logic ก่อนเขียนโค้ด

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) To plan control flow and check logic before codingเพื่อวางแผน control flow และตรวจ logic ก่อนเขียนโค้ด
    Correct! A flowchart plans sequence, decisions, and loops.ถูกต้อง! flowchart ช่วยวางลำดับ การตัดสินใจ และการวนซ้ำ
  • (B) To replace all program testingเพื่อแทนที่การทดสอบโปรแกรมทั้งหมด
    Wrong: you still need to test after coding.ผิด: ยังต้องทดสอบโปรแกรมหลังเขียนโค้ด
  • (C) Because Python runs only flowchart filesเพราะ Python รันได้เฉพาะไฟล์ flowchart
    Wrong: Python runs .py source files, not diagrams.ผิด: Python รันไฟล์ .py ไม่ใช่แผนภาพ
  • (D) To avoid structured programmingเพื่อไม่ต้องใช้ structured programming
    Wrong: flowcharts support structured programming.ผิด: flowchart สนับสนุน structured programming

ข้อ 2

2 / 10

What shape is the Terminator symbol?สัญลักษณ์ Terminator มีรูปทรงใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (B) Rounded rectangle (pill shape)สี่เหลี่ยมมุมโค้ง (pill)

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Diamondสี่เหลี่ยมข้าวหลามตัด
    Wrong: a diamond is the Decision symbol.ผิด: diamond คือ Decision
  • (B) Rounded rectangle (pill shape)สี่เหลี่ยมมุมโค้ง (pill)
    Correct! START/STOP use a pill-shaped terminator.ถูกต้อง! START/STOP ใช้รูป pill
  • (C) Parallelogramสี่เหลี่ยมด้านขนาน
    Wrong: a parallelogram is Data I/O.ผิด: parallelogram คือ Data I/O
  • (D) Circleวงกลม
    Wrong: a circle is an on-page connector.ผิด: วงกลมคือ on-page connector

ข้อ 3

3 / 10

What shape represents Data (Input/Output)?สัญลักษณ์ Data (Input/Output) มีรูปทรงใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (C) Parallelogramสี่เหลี่ยมด้านขนาน

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Rounded rectangleสี่เหลี่ยมมุมโค้ง
    Wrong: that is the Terminator.ผิด: นั่นคือ Terminator
  • (B) Plain rectangleสี่เหลี่ยมธรรมดา
    Wrong: a plain rectangle is Process.ผิด: สี่เหลี่ยมธรรมดาคือ Process
  • (C) Parallelogramสี่เหลี่ยมด้านขนาน
    Correct! Input/Output uses a parallelogram.ถูกต้อง! I/O ใช้ parallelogram
  • (D) Pentagonรูปห้าเหลี่ยม
    Wrong: a pentagon is an off-page connector.ผิด: pentagon คือ off-page connector

ข้อ 4

4 / 10

Which symbol holds the condition number % 2 == 0?เงื่อนไข number % 2 == 0 ใน flowchart ควรอยู่ในสัญลักษณ์ใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (D) DecisionDecision

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) ProcessProcess
    Wrong: Process is for calculations, not tests.ผิด: Process ใช้กับการคำนวณ ไม่ใช่ทดสอบเงื่อนไข
  • (B) Data I/OData I/O
    Wrong: I/O reads or writes data.ผิด: I/O ใช้รับหรือส่งข้อมูล
  • (C) TerminatorTerminator
    Wrong: Terminator marks START/STOP.ผิด: Terminator คือ START/STOP
  • (D) DecisionDecision
    Correct! Yes/No tests go in a decision diamond.ถูกต้อง! เงื่อนไข Yes/No อยู่ใน diamond

ข้อ 5

5 / 10

Which symbol fits the step F = (float(C)*1.8)+32?ขั้นตอน F = (float(C)*1.8)+32 ควรใช้สัญลักษณ์ใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (A) ProcessProcess

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) ProcessProcess
    Correct! A calculation belongs in a Process rectangle.ถูกต้อง! การคำนวณอยู่ใน rectangle ของ Process
  • (B) DecisionDecision
    Wrong: there is no condition to branch on.ผิด: ไม่มีเงื่อนไขให้เลือกเส้นทาง
  • (C) On-page connectorOn-page connector
    Wrong: connectors link pages, not compute.ผิด: connector ใช้เชื่อมหน้า ไม่ใช่คำนวณ
  • (D) FlowlineFlowline
    Wrong: a flowline is an arrow, not a calculation block.ผิด: flowline เป็นลูกศร ไม่ใช่บล็อกคำนวณ

ข้อ 6

6 / 10

How does a Sub-process differ from a Process?Sub-process ต่างจาก Process อย่างไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (B) Sub-process calls a function or chart defined elsewhereSub-process เรียกฟังก์ชันหรือแผนย่อยที่นิยามไว้ที่อื่น

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Sub-process is a diamond; Process is a pillSub-process เป็น diamond ส่วน Process เป็น pill
    Wrong: both use rectangles (sub-process has double bars).ผิด: ทั้งคู่เป็นรูปสี่เหลี่ยม (sub-process มีขอบคู่)
  • (B) Sub-process calls a function or chart defined elsewhereSub-process เรียกฟังก์ชันหรือแผนย่อยที่นิยามไว้ที่อื่น
    Correct! For example, calling find_total(scores).ถูกต้อง! เช่น เรียก find_total(scores)
  • (C) Process is only used for START/STOPProcess ใช้ได้เฉพาะ START/STOP
    Wrong: START/STOP use the Terminator.ผิด: START/STOP ใช้ Terminator
  • (D) No difference — they are interchangeableไม่มีความต่าง — ใช้แทนกันได้
    Wrong: they mean different things.ผิด: ความหมายต่างกัน

ข้อ 7

7 / 10

What is the difference between on-page and off-page connectors?On-page connector กับ Off-page connector ต่างกันอย่างไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (C) On-page uses matching circles on the same page; off-page continues on another pageOn-page เป็นวงกลมคู่ในหน้าเดียวกัน; off-page ไปหน้าอื่น

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) On-page is a pentagon; off-page is a circleOn-page เป็น pentagon; off-page เป็นวงกลม
    Wrong: shapes are reversed — circles are on-page.ผิด: สลับรูปทรง — วงกลมคือ on-page
  • (B) Both are parallelograms differing only in colourทั้งคู่เป็น parallelogram ต่างกันแค่สี
    Wrong: they use different shapes.ผิด: รูปทรงต่างกัน
  • (C) On-page uses matching circles on the same page; off-page continues on another pageOn-page เป็นวงกลมคู่ในหน้าเดียวกัน; off-page ไปหน้าอื่น
    Correct! Off-page is often a pentagon with a page number.ถูกต้อง! off-page มักเป็น pentagon พร้อมเลขหน้า
  • (D) Off-page replaces Decision onlyOff-page ใช้แทน Decision เท่านั้น
    Wrong: connectors continue flow, not test conditions.ผิด: connector ใช้ต่อเส้นทาง ไม่ใช่ทดสอบเงื่อนไข

ข้อ 8

8 / 10

What is a flowline used for?Flowline ใช้ทำอะไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (D) Show execution order between symbols with arrowsแสดงลำดับการทำงานระหว่างสัญลักษณ์ด้วยลูกศร

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Store input data from the userเก็บข้อมูล input จากผู้ใช้
    Wrong: input uses the Data I/O symbol.ผิด: input ใช้สัญลักษณ์ Data I/O
  • (B) Show the name of a sub-functionแสดงชื่อฟังก์ชันย่อย
    Wrong: function names go in Sub-process blocks.ผิด: ชื่อฟังก์ชันอยู่ใน Sub-process
  • (C) Mark the START of the programทำเครื่องหมาย START ของโปรแกรม
    Wrong: START uses a Terminator.ผิด: START ใช้ Terminator
  • (D) Show execution order between symbols with arrowsแสดงลำดับการทำงานระหว่างสัญลักษณ์ด้วยลูกศร
    Correct! Flowlines link symbols and show direction.ถูกต้อง! flowline เชื่อมและบอกทิศทาง

ข้อ 9

9 / 10

Which symbol marks START and STOP in the main program?จุด START และ STOP ของโปรแกรมหลักใช้สัญลักษณ์ใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (A) TerminatorTerminator

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) TerminatorTerminator
    Correct! Pill shapes labelled START/STOP.ถูกต้อง! pill labelled START/STOP
  • (B) ProcessProcess
    Wrong: Process is for middle steps.ผิด: Process ใช้กับขั้นตอนกลาง
  • (C) DecisionDecision
    Wrong: Decision tests a condition.ผิด: Decision ใช้ทดสอบเงื่อนไข
  • (D) FlowlineFlowline
    Wrong: a flowline is a connecting arrow.ผิด: flowline เป็นลูกศรเชื่อม

ข้อ 10

10 / 10

How are Frank and Lillian Gilbreth related to flowcharts?Frank และ Lillian Gilbreth เกี่ยวข้องกับ flowchart อย่างไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (B) They introduced flow process charts in 1921พวกเขานำเสนอ flow process chart ในปี 1921

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) They wrote the first Python languageพวกเขาเขียนภาษา Python ตัวแรก
    Wrong: Python was developed much later.ผิด: Python ถูกพัฒนาทีหลัง
  • (B) They introduced flow process charts in 1921พวกเขานำเสนอ flow process chart ในปี 1921
    Correct! As noted in the Did you know? box.ถูกต้อง! ตามบท Did you know?
  • (C) They designed all eight ANSI symbolsพวกเขาออกแบบสัญลักษณ์ ANSI ทั้ง 8 ชนิด
    Wrong: ANSI symbols came from later standards.ผิด: สัญลักษณ์ ANSI มาจากมาตรฐานภายหลัง
  • (D) They used flowcharts only for binary mathพวกเขาใช้ flowchart เฉพาะกับฐานสอง
    Wrong: their work was on general workflows.ผิด: งานของพวกเขาเกี่ยวกับ workflow ทั่วไป