Architect 2 Checkpoint

The Logic Coder

แบบทดสอบย่อยเพื่อก้าวสู่ The Architect 3

Part 1: เงื่อนไขและลูป (5 คะแนน)

1. คำสั่งใดใช้ทำซ้ำแบบ "วนไปเรื่อยๆ ไม่มีที่สิ้นสุด"? (Forever Loop)

2. เครื่องหมาย "==" ใน Python หมายถึงอะไร?

3. อะไรสำคัญที่สุดในการเขียนเงื่อนไข if ใน Python?

4. ฟังก์ชัน wait_for_seconds(2) ทำอะไร?

5. หากต้องการใช้ Distance Sensor วัดระยะทาง ใช้คำสั่งใด?

Part 2: เครื่องตรวจจับวัตถุ (5 คะแนน)

Scenario: Basic Obstacle Avoider

"เขียนโปรแกรมให้หุ่นยนต์หยุดเมื่อเจอสิ่งกีดขวางด้านหน้า"

ภารกิจ (Complete the Code):

from spike import PrimeHub, DistanceSensor, Motor

dist = DistanceSensor('A')
motor = Motor('B')

while True:
    # อ่านค่าระยะทาง
    distance = dist.get_distance_cm()

    # ถ้า น้อยกว่า 10 ซม. ให้หยุด
    if distance < 10 and distance is not None:
        motor.stop()
    # ถ้าไม่ใช่ ให้วิ่งไปเรื่อยๆ
    else:
        motor.start()
                        

* นักเรียนต้องอธิบายการทำงานของ While True และ If/Else ให้ครูฟัง