Night 24: Move around
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
Tonight: move around
- Your pet has a map. Tonight it walks around on it!
- Nothing new to learn: you use
INPUT,WHILEandIFon a map.
Words for tonight
| Word | Meaning |
|---|---|
| move | go from one place to another |
| position | where something is: X and Y |
| command | a word that tells the program what to do |
Where is the pet?
- Two numbers say where the pet is:
X(left–right) andY(up–down). Y = 1is the top row. So "up" makesYsmaller.
| Move | Change |
|---|---|
| up | Y ← Y - 1 |
| down | Y ← Y + 1 |
| left | X ← X - 1 |
| right | X ← X + 1 |

Choose with CASE OF
- One variable, many choices:
CASE OFis neat for commands.
DECLARE X, Y : INTEGER
DECLARE Move : STRING
X ← 3
Y ← 3
Move ← "up"
CASE OF Move
"up" : Y ← Y - 1
"down" : Y ← Y + 1
"left" : X ← X - 1
"right" : X ← X + 1
ENDCASE
OUTPUT "Now at ", X, " ", Y
- In the tasks, the moves come from
INPUTuntil the player typesstop.
Stay on the map
- Check the edge before you move.
DECLARE X : INTEGER
DECLARE Move : STRING
X ← 1
Move ← "left"
IF Move = "left" AND X > 1 THEN
X ← X - 1
ENDIF
OUTPUT X
Xstays 1: the pet is already at the left wall.- Now take your pet for a walk!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet is at X ← 3, Y ← 3. Read one move: up, down, left 또는 right. Change X 또는 Y, then output them. left gives 2 3. up makes Y smaller.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Now read moves again and again, until the move is stop. Change X 및 Y for each move. At the end, output X 및 Y.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
The map is 5 × 5: X 및 Y go from 1 부터 5. Do not let the pet walk off the map. A move into the wall does nothing.
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
After the moves, draw the 5 × 5 map: P where the pet is, . everywhere else. Row Y and column X hold the P.
출력을 보려면 '실행'을 클릭하세요.