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). - On a screen,
y = 0is the top row. So "up" makesysmaller.
| Move | Change |
|---|---|
| up | y = y - 1 |
| down | y = y + 1 |
| left | x = x - 1 |
| right | x = x + 1 |

The game loop
- Read a command, change the world, repeat. Every game works like this.
x = 2
y = 2
moves = ["up", "left", "left"]
for move in moves:
if move == "up":
y = y - 1
elif move == "left":
x = x - 1
print("Now at", x, y)
- In the tasks, the moves come from
input()until the player typesstop.
Stay on the map
- Check the edge before you move.
x = 0
move = "left"
if move == "left" and x > 0:
x = x - 1
print(x)
xstays 0: the pet is already at the left wall.- Now take your pet for a walk!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet is at x = 2, y = 2. Read one move: up, down, left 또는 right. Change x 또는 y, then print them. left gives 1 2. 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, print x 및 y.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
The map is 5 × 5: x 및 y go from 0 부터 4. 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.
출력을 보려면 '실행'을 클릭하세요.