Lesson 10: Final challenges
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Final challenges
- Now put it all together: loops, functions, sensors and
if. - First plan the route on paper. Then write it step by step and press Run often.
- In the second challenge the gap in the wall moves. Only a program that looks with its sensor works on every map.
Words for this lesson
| Word | Meaning |
|---|---|
| maze | walls with one way through |
| gap | an open space in a wall |
| break | leave a loop at once |
| while True | a loop that only break can end |
English
Look, then move
from vexcode_vr import *
def main():
while True:
if front_distance.get_distance(MM) < 300:
break
drivetrain.drive_for(FORWARD, 100, MM)
brain.print("wall ahead")
vr_thread(main)
- The loop drives 100 mm at a time. When a wall is closer than 300 mm,
breakends the loop.
English
In the exam
- 0478/12/O/N/23 Q7(b): a train door may close only when no passenger is in the doorway; explain how a sensor and a microprocessor check this (6 marks). Mark scheme points include: a proximity or infrared sensor; it sends data to the microprocessor; the microprocessor compares the data with a stored value; if it is safe, a signal goes to an actuator to close the door; if not, the door stays open; the process repeats. Your robot does the same:
front_distanceis the sensor, 300 mm is the stored value, and the loop repeats until it is safe to stop.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Drive through the zigzag to the goal in the top-right corner without touching a wall. The route: 1500 mm right, up 550, 1500 left, up 500, 1500 right, up 500. Use a function for one zig and one zag if you like.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
A wall crosses the playground with one gap, in a different place on each map. Face right and move 100 mm at a time; after each step, turn left and look up. When the distance is more than 1000 mm, the gap is in front: move 150 mm more to its middle, then drive 1300 mm up to the goal.
출력을 보려면 '실행'을 클릭하세요.