Lesson 10: Final challenges
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 |
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.
Độ khó 3/5 · 200 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
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.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 3/5 · 200 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
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.
Nhấn Chạy để xem kết quả ở đây.