#295. Walking in a loop
When the green flag is clicked, this script runs. What is the cat's **x** position?
when green flag clicked go to x: (0) y: (0) point in direction (90) repeat (2) move (20) steps end
import math
# The sprite's (cat's) position, direction and size
x_pos = 0
y_pos = 0
direction = 90
# When the green flag is clicked
x_pos, y_pos = 0, 0
direction = 90
for _ in range(2):
x_pos += 20 * math.sin(math.radians(direction))
y_pos += 20 * math.cos(math.radians(direction))
// The sprite's (cat's) position, direction and size
let x_pos = 0, y_pos = 0, direction = 90;
// When the green flag is clicked
x_pos = 0;
y_pos = 0;
direction = 90;
for (let i = 0; i < 2; i++) {
x_pos += 20 * Math.sin(direction * Math.PI / 180);
y_pos += 20 * Math.cos(direction * Math.PI / 180);
}
💡 Not sure? Build it in Scratch and try it out.