0

I am trying to set my init and when trying to set (x,y), I am getting an invalid Syntax error on the open parentheses on the coordinates.

I feel like this is going to be an obvious mistake but I've been looking at it too long and could use some fresh eyes...

def __init__(self, (x,y), size, color = (255,255,255)):
        self.x = x
        self.y = y
        self.size = size
        self.color = color
        self.width = width

2 Answers2

3

Since x and y are elements of a tuple (if that's what you're trying to create) you don't need to assign individual element in parameters.

def __init__(self, coordinates, size, color = (255,255,255)):
        self.x = coordinates[0]
        self.y = coordinates[1]
        self.size = size
        self.color = color
        self.width = width
oo00oo00oo00
  • 473
  • 6
  • 16
  • 1
    Or `self.x, self.y = coordinates`. Which has the advantage of throwing an exception if there are more than 2 values in the list/tuple/whatever. – Aran-Fey Jul 05 '19 at 22:28
-1

You have to write __init__(self, v , size, color = (255,255,255)) and pass every vas a list.

def __init__(self, v, size, color = (255,255,255)):
        self.x = v[0] #first coordinate of v
        self.y = v[1] #second coordinate of v
        self.size = size
        self.color = color
        self.width = width
L F
  • 548
  • 1
  • 7
  • 22