0

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.

  • `moveturtle(wn, t, o)` requires three arguments to be passed. Clearly, when you write`moveturtle(y)` it does not satisfy the *three arguments* requirement, because `y` is a single argument. You wrote the `moveturtle()` function, so you should know what the three values you expect it to receive should be and where they come from, shouldn't you? (Hint: `turtlesetup()`'s last line says `return(wn, t, o)`, but you assign that return value to `y` with `y = turtlesetup()`. Does that seem right to you?) – Ken White Jun 09 '17 at 02:19
  • True. I was somehow expecting return(wn,t,o) to fill y. Sort of like y = wn,t,o. Then, I pass y into moveturtle(y) . – Apprentice_Programmer Jun 09 '17 at 02:24
  • So how do I extract the wn,t,o objects from setups turtle and get them to exist in main? I believe that's the question now. After that, I can pass it into moveturtle no problem. When I put y = turtlesetup(), I was trying to accomplish the tuple option mentioned here: https://stackoverflow.com/questions/354883/how-do-you-return-multiple-values-in-python – Apprentice_Programmer Jun 09 '17 at 02:28

1 Answers1

1

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 )
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101