Search code examples
pythonfunctionreturntuples

TypeError: unsupported operand type(s) for +: 'int' and 'tuple'


I'm trying to get the values of vector and degrees for each value of time but i get stuck with this error:

TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

If i follow the traceback i get to x = -0,3*(t**2)+(7,2*t)+28 but how come that's a int = tuple?

Traceback:

Traceback (most recent call last):
  File "testgraph.py", line 53, in <module>
    vector, degrees = vector_position(t)
  File "testgraph.py", line 14, in vector_position
    x = function_positionX(t)
  File "testgraph.py", line 5, in function_positionX
    x = -0,3*(t**2)+(7,2*t)+28 

Code:

import numpy as np
import math

def function_positionX(t):
    x = -0,3*(t**2)+(7,2*t)+28
    return x

def function_positionY(t):
    y = 0,22*(t**2)-(9,1*t)+30
    return y

def vector_position(t):
    x = function_positionX(t)
    y = function_positionY(t)
    v = math.sqrt((x**2)+(y**2))
    d = np.arctan2(y/x)
    return v,d

def function_speedX(t):
    x = -0,62*t+7,2
    return x

def function_speedY(t):
    y = 0,44*t-9,1
    return y

def vector_speed(t):
    x = function_speedX(t)
    y = function_speedY(t)
    v = math.sqrt((x**2)+(y**2))
    d = np.arctan2(y/x)
    return v,d

def function_accelX():
    a = -0,62
    return a

def function_accelY():
    a = 0,44
    return a

def vector_accel(t):
    x = function_accelX()
    y = function_accelY()
    v = math.sqrt((x**2)+(y**2))
    d = np.arctan2(y/x)
    return v,d


for t in range(0,15):
    print("For time: ", t)
    vector, degrees = vector_position(t)
    print(vector,degrees)
    vector, degrees = vector_speed(t)
    print(vector,degrees)
    vector, degrees = vector_accel(t)
    print(vector,degrees)

Solution

  • I'm no expert, but when you write 0,3 do you mean 0.3? We don't usually use commas in numbers for a decimal point!

    That's I think why you are getting the mentioned error, so change the commas to dots and try again.

    Try spending time getting comfortable with python itself and programming before diving into more advanced things.