Untitled
unknown
python
4 years ago
891 B
3
Indexable
# Here's a class Turtle that represents the turtle that is moving in the 2D world. # The turtle can move in four directions: up, down, left and right. # The turtle can make n steps at a time and the only restrictions are that x≥0,y≥0. class Turtle: def __init__(self, x, y): # the initial coordinates of the turtle self.x = x self.y = y def move_up(self, n): self.y += n def move_down(self, n): self.y = 0 if n > self.y else self.y - n def move_right(self, n): self.x += n def move_left(self, n): self.x = 0 if n > self.x else self.x - n # What will be the coordinates of the Turtle # leo after these movements? Choose the pair (x, y). leo = Turtle(1, 1) leo.move_up(7) # y = 7 leo.move_left(5) # x = 0 leo.move_down(4) # y = 7 - 4 = 3 leo.move_right(6) # x = 6 # ( 6, 3) dar raspunsul cica e (6, 4)
Editor is loading...