A_S - 1 year ago 75

Python Question

I'm working with python 3.4 in pygame but I get a syntax error because of the second bracket in the function definition

How can I fix this?

`def addVectors((angle1, length1), (angle2, length2)):`

x = math.sin(angle1) * length1 + math.sin(angle2) * length2

y = math.cos(angle1) * length1 + math.cos(angle2) * length2

length = math.hypot(x, y)

angle = 0.5 * math.pi - math.atan2(y, x)

return (angle, length)

Answer Source

If your function is being passed in 2 tuples, you should extract the individual values from the tuples like so:

```
def addVectors(vector1, vector2):
angle1, length1 = vector1
angle2, length2 = vector2
x = math.sin(angle1) * length1 + math.sin(angle2) * length2
y = math.cos(angle1) * length1 + math.cos(angle2) * length2
length = math.hypot(x, y)
angle = 0.5 * math.pi - math.atan2(y, x)
return (angle, length)
```