Python simple tortoise walk

I am having trouble trying to complete a python tortoise program. When I try to enter the x and y coordinates, as well as the radius value for a function like t.drawSnowman (x = 25, y = 25, radius = 25), the program works erroneously when entering values. But if I do not specify the parameters above and instead just use t.drawSnowman (), then the program works as intended, but I am not able to create various cases of a snowman.

I would really like to help figure out how to enter parameters and still have a program function.

here is my code

import turtle

class MyTurtle(turtle.Turtle):
""""""


def __init__(self):
    """Turtle Constructor"""
    turtle.Turtle.__init__(self, shape="turtle")

def drawNose(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draw nose '''
    self.pendown()
    self.goto(-(radius) * (0.25),(radius * 6)+(radius * 4)+(radius))
    self.goto(0,(radius * 6)+(radius * 4)+(radius)+(radius * (0.25)))
    self.goto((radius) * (0.25),(radius * 6)+(radius * 4)+(radius))
    self.goto(0,(radius * 6)+(radius * 4)+(radius))
    self.penup()

def leftEye(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draw left eye'''
    self.pendown()
    self.circle(radius*(.25))
    self.penup()
def rightEye(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draw right eye'''
    self.pendown()
    self.circle(radius*(.25))
    self.penup()
def bottomOfHat(self, x=0, y=0, radius = 15, circle_color = "black"):
    ''' draw the long part of the hat at the bottom '''
    self.goto(0,(radius * 6)+(radius * 4)+(radius * 2))
    self.pendown()
    self.goto(-(radius),(radius * 6)+(radius * 4)+(radius * 2))
    self.goto(-(radius),(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
    self.goto(radius,(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
    self.goto(radius,(radius * 6)+(radius * 4)+(radius * 2))
    self.goto(0,(radius * 6)+(radius * 4)+(radius * 2))
    self.penup()

def topOfHat(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draw the top bigger part of the hat'''
    self.goto(radius*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))
    self.pendown()
    self.goto(radius*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * 2))
    self.goto(-(radius)*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * 2))
    self.goto(-(radius)*(.75),(radius * 6)+(radius * 4)+(radius * 2)+(radius * (0.5)))

def bottomCircle(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draws the bottom circle'''
    self.pendown()
    self.circle(radius * 3)
    self.penup()
def middleCircle(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draw the middle circle'''
    self.pendown()
    self.circle(radius * 2)
    self.penup()
def topCircle(self, x=0, y=0, radius = 15, circle_color = "black"):
    '''draw the top circle'''
    self.pendown()
    self.circle(radius)
    self.penup()
def drawSnowman(self, x=0, y=0, radius = 15, circle_color = "black"):
    self.bottomCircle()
    self.goto(0,radius * 6)
    self.middleCircle()
    self.goto(0,(radius * 6)+(radius * 4))
    self.topCircle()
    self.goto(-(radius) * (0.5),(radius * 6)+(radius * 4)+(radius))
    self.leftEye()
    self.goto((radius) * (0.5),(radius * 6)+(radius * 4)+(radius))
    self.rightEye()
    self.goto(0,(radius * 6)+(radius * 4)+(radius))
    self.drawNose()
    self.bottomOfHat()
    self.topOfHat()



t = MyTurtle()
t.hideturtle()
radius = 15
t.drawSnowman(x = 25,y = 25,radius = 25)

This is an image of a snowman when I use the t.drawsnowman parameters (x = 25 y = 25 radius = 25) messed up snowman

This is a snowman when I don't need t.drawsnowman () parameters correct snowman

+4
1

, ( ).

  • t.drawSnowman(), radius 15.
  • bottomCircle(), radius * 3= 45
  • radius * 6= 90 y ( "" )
  • middleCircle(), radius * 2= 30
  • ...

, , :

  • t.drawSnowman(x = 25,y = 25,radius = 25), radius 25.
  • bottomCircle(), radius * 3= 45. , radius 15, , drawSnowman, bottomCircle.
  • radius * 6= 150 y ( )
  • middleCircle(), radius * 2= 30. , radius 15.
  • ...

, , radius, drawSnowman, .

+2

Source: https://habr.com/ru/post/1534212/


All Articles