Lesson 20: Warehouse mission
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
The warehouse mission
- The warehouse robot has a big job, and it needs all your skills: follow the tape, find the door, count the parcels.
- The routes and the number of parcels are different on every map, so the robot must use its sensors all the way.
- You build the program from functions: one function for each job.
Words for this lesson
| Word | Meaning |
|---|---|
| mission | an important job with several parts |
| function | a named block of code: def follow_tape(): |
| call | run a function: follow_tape() |
| return | send a value back from a function |
English
The plan
| Job (lesson) | Code |
|---|---|
| follow the tape (12) | follow_tape() |
| face the parcels (15) | turn_to_heading(90, …) |
| count red parcels (16) | count_parcels() |
| report (16) | brain.print(...) |
English
A function that gives back a number
from vexcode_vr import *
def double(n):
return n * 2
def main():
answer = double(21)
brain.print(answer)
vr_thread(main)
double(21)works out 21 × 2 and returns 42.answerkeeps it, and the brain prints 42.
English
In the exam
- 0478/22/F/M/23 Q10(b): define a function
Same(A, B)that returns TRUE or FALSE, then call it with X and Y and store the return value in Z. It is yourparcels = count_parcels(): the function sends a value back withRETURN, and the call keeps it in a variable. - A procedure does a job and returns nothing (like
follow_tape()); a function returns a value (likecount_parcels()).
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
This mission puts everything together. First, write a function follow_tape() that follows the black tape until the down eye sees the green door (your tape follower from lesson 12 works). Then call it in main. Each map has a different route.
実行ボタンをクリックして出力を確認してください。
難易度 5/5 · 400 コイン + 今日初回達成時の小ボーナス
At the green door, the parcels wait in a row to the right. Write count_parcels(): drive 50 mm at a time until the wall is 100 mm away, count the red parcels (drive 200 mm off each one) and return the count. In main: follow the tape, face right with turn_to_heading(90, DEGREES), count, and print Parcels: and the number.
実行ボタンをクリックして出力を確認してください。