Apprentice_Programmer
Apprentice_Programmer

Reputation: 95

I cannot figure out how to pass a turtle and a screen from one function to another in my main function

I am very new to programming to start. I will try to be clear. This may be not be proper etiquette but I am still curious how I should accomplish what I am trying to do. Any help would be appreciated. Here's my main function.

def main():

     y = turtlesetup()
     moveturtle(y)

     wn.exitonclick()

Here is turtlesetup:

def turtlesetup():

     t = turtle.Turtle()
     o = turtle.Turtle()
     wn = turtle.Screen()



     t.shape('turtle')
     o.shape('turtle')
     o.color("red")


     starttx = random.randrange(-50,50)
     startty = random.randrange(-50,50)

     startox = random.randrange(-50,50)
     startoy = random.randrange(-50,50)

     o.penup()
     o.setpos(startox,startoy)
     o.pendown()

     t.penup()
     t.setpos(starttx,startty)
     t.pendown()

     return(wn,t,o)

And moveturtle:

def moveturtle(wn,t,o):

     while isInScreen(wn,t,o):
         angle = random.randrange(1, 361)
         angleo = random.randrange(1,361)

         t.right(angle)
         o.right(angleo)

         o.forward(50)
         t.forward(50)

After turtlesetup is called, it moves onto moveturtle but I believe I am getting moveturtle() missing 2 required positional arguments: 't' and 'o' . I believe this is because I need pass the turtle objects and screen object from turtlesetup into moveturtle and I am not doing it correctly. Forgive my unimaginative variables and possibly improper use of functions and the main function. Thanks for you time.

Upvotes: 0

Views: 672

Answers (1)

Scott Hunter
Scott Hunter

Reputation: 49896

moveturtle takes 3 arguments, but you are only passing it 1: the tuple of 3 elements that was returned by turtlesetup.

You could fix this by calling moveturtle like so:

moveturtle( y[0], y[1], y[2] )

Or:

moveturtle( *y )

Upvotes: 1

Related Questions