World 3: Read the route
A note with a route
- Now your pet has a route note: a string like
"RRDR". - Your code reads the note letter by letter and prints the real moves.
Words for this world
| Word | Meaning |
|---|---|
| route | the way from one place to another |
| letter | one character in a string |
| decide | choose what to do; if decides |
Turn letters into moves
route = "RRD"
for letter in route:
if letter == "R":
print("right")
elif letter == "D":
print("down")
- The loop visits every letter. The
ifdecides what to print.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Your pet has a route note: route = "RRRR". R means right. Go through the letters with a loop, and print right for each R.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Now the route has two letters: route = "RDRDR". R means right and D means down.
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
Use all four letters: R right, L left, U up, D down. The route is "DDRRUURR".
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
Someone wrote extra x letters in the route: "RxRxDxR". An x means nothing. Print a move only for R và D.
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 short route: "R3D2R1". Each letter comes with a number: how many times to move. So R3 means right, right, right.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 4/5 · 280 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
The treasure route: "D1R2X1R1". X means dig. Read each letter and number as before.
Nhấn Chạy để xem kết quả ở đây.