just wanted to know how to write the getpos() command which must return an (x,y) tuple of the current position.
does it start like this:
def getpos(x 100, y 100)
not sure need help
just wanted to know how to write the getpos() command which must return an (x,y) tuple of the current position.
does it start like this:
def getpos(x 100, y 100)
not sure need help
This is a bit underspecified, but this might work:
def getpos(self):
return (self.x, self.y)
This is how to return a tuple, from values assumed to be instance variables.
In Python you can't force a return type on a function from its header. The return type can change from one call to another. When you write:
def getpos(x,y):
It means that the function receives 2 parameters, that inside the function are called x & y. No type is forced on them either. Just write the function so it returns the tuple, e.g.:
def getpos():
x = 100
y = 100
return (x,y)
The syntax that you used (def getpos(x 100, y 100) ) does not have any meaning that I know.