Lesson 7: Decide with if
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Decide with if
iflets the robot choose. It looks with a sensor, then does one thing or the other.elseis what happens when theiftest is false.
Words for this lesson
| Word | Meaning |
|---|---|
| if | do this only when the test is true |
| else | otherwise, do this |
| open | no wall close in front |
| blocked | a wall close in front |
English
Which way is open?
from vexcode_vr import *
def main():
if front_distance.get_distance(MM) > 500:
brain.print("open")
else:
brain.print("blocked")
vr_thread(main)
brain.printwrites on the robot's screen, shown under the playground.- The test
> 500asks: is the wall more than 500 mm away?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
One side is blocked by a wall, the other is open. Turn left and look. If the distance is more than 500 mm, drive 800 mm. Else turn round (180 degrees) and drive 800 mm the other way.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Drive up to the wall (stop at 100 mm), turn right, then drive to the next wall the same way. Write a function drive_to_wall() and call it twice. The goal is in the corner.
출력을 보려면 '실행'을 클릭하세요.