Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Les16_2 #31

Open
kostyria opened this issue Apr 3, 2023 · 0 comments
Open

Les16_2 #31

kostyria opened this issue Apr 3, 2023 · 0 comments

Comments

@kostyria
Copy link
Owner

kostyria commented Apr 3, 2023

class Turtle:
def init(self, x=0, y=0, s=1):
self.x = x
self.y = y
self.s = s

def go_up(self):
    self.y += self.s

def go_down(self):
    self.y -= self.s

def go_left(self):
    self.x -= self.s

def go_right(self):
    self.x += self.s

def evolve(self):
    self.s += 1

def degrade(self):
    if self.s > 1:
        self.s -= 1
    else:
        raise ValueError("S should be more than 0")

def count_moves(self, x2, y2):
    dist_x = abs(self.x - x2)
    dist_y = abs(self.y - y2)
    moves = (dist_x + dist_y) / self.s
    if moves % 1 != 0:
        moves = int(moves) + 1
    else:
        moves = int(moves)
    return moves

turtle = Turtle(0, 0, 1)
print(turtle.count_moves(-5, 7))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant