Trying to do an if statment with positions

I am using the turtle module, and I wanna do if some turtle is in a position do that. How can I do this?

with the 69 position

jokes aside here is a guide that might help u

1 Like

Nope. Didn’t have anything anything about that.

Anything good. I don’t know how to do.

Could you please explain more simply exactly what you’re trying to do? What do you want to do when what exactly is true?

Basically, if, in turtle module, a turtle reaches the position (x, y) print (…). I don’t know how to do that.

hmmmm okay let me see the error

Why when I put this:

if alex == alex.position(500, 0):
   print("alex")

appears me this:

TypeError: pos() takes 1 positional argument but 3 were given

yes you passed n two args in the parenthesis

So, how should I do that?

well try if alex ==alex.position(500,0):
print(alex)

What happens is the same.

it should try to run according to the variable you created

So, what should i do?

remove the quotation marks from the name alex

I did it and occurred the same thing. And why should I do that if i just wanna, if alex go to that position print his name?

can you privately send me the complete code let me go through it and see

That doesn’t matters in this case.

OK, a couple of things:

  1. The pos() method on the turtle returns a single object somewhat like a tuple or a list containing 2 values.

  2. Any method on a Python class/object always has at least 1 parameter, an invisible “self” paramter that is automatically supplied by the Python runtime. This self parameter is a handle to the object to which the method being called belongs. So in the case of calling say turtle.pos() to retrieve the current position of the turtle, inside the pos() method, the “self” paramter therefore is the turtle itself.

Consequently, when the Python interpreter is saying:
TypeError: pos() takes 1 positional argument but 3 were given
… this tells you several things:

  1. pos() doesn’t actually have any parameters as it has only one actual parameter, e.g. which is/must be the default self parameter.

  2. You should therefore not be trying to pass stuff to pos()

  3. You can use functions like help(), dir() and type() to inspect objects in the Python interpreter (REPL - the “Read Evaluate Print Loop”)

Try the following commands in a Python interpreter (I show the full session, including my interpreter responses!):

C:\Users\username>python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
>>> alex = turtle.Turtle()
>>> dir(alex)
['DEFAULT_ANGLEOFFSET', 'DEFAULT_ANGLEORIENT', 'DEFAULT_MODE', 'START_ORIENTATION', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_angleOffset', '_angleOrient', '_cc', '_clear', '_clearstamp', '_color', '_colorstr', '_creatingPoly', '_degreesPerAU', '_delay', '_drawing', '_drawturtle', '_fillcolor', '_fillitem', '_fillpath', '_fullcircle', '_getshapepoly', '_go', '_goto', '_hidden_from_screen', '_mode', '_newLine', '_orient', '_outlinewidth', '_pen', '_pencolor', '_pensize', '_poly', '_polytrafo', '_position', '_reset', '_resizemode', '_rotate', '_screen', '_setDegreesPerAU', '_setmode', '_shapetrafo', '_shearfactor', '_shown', '_speed', '_stretchfactor', '_tilt', '_tracer', '_undo', '_undobuffersize', '_undogoto', '_update', '_update_data', '_write', 'back', 'backward', 'begin_fill', 'begin_poly', 'bk', 'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color', 'currentLine', 'currentLineItem', 'degrees', 'distance', 'dot', 'down', 'drawingLineItem', 'end_fill', 'end_poly', 'fd', 'fillcolor', 'filling', 'forward', 'get_poly', 'get_shapepoly', 'getpen', 'getscreen', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'items', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'reset', 'resizemode', 'right', 'rt', 'screen', 'screens', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'stampItems', 'tilt', 'tiltangle', 'towards', 'turtle', 'turtlesize', 'undo', 'undobuffer', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']
>>> help(turtle.pos)
Help on function pos in module turtle:

pos()
    Return the turtles current location (x,y), as a Vec2D-vector.

    Aliases: pos | position

    No arguments.

    Example:
    >>> pos()
    (0.00, 240.00)

>>> if turtle.pos() == (0,0): print("Turtles position is (0,0)")
...
Turtle's position is (0,0)
>>> type(turtle.pos())
<class 'turtle.Vec2D'>
>>>

I show how to do what you want by comparing to a tuple value (e.g. the (0,0) bit) towards the bottom of the above session in an if statement.

Hope that helps! :slight_smile: