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'
类型错误:+:'int'和'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?
如果我沿着回溯,我得到x = -0 3*(t* 2)+(7 2*t)+28但为什么这是一个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)
1 个解决方案
#1
0
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!
我不是专家,但是当你写0 3时,你是说0。3吗?我们通常不会用逗号来表示小数点!
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.
在深入研究更高级的东西之前,试着花点时间熟悉python本身和编程。
#1
0
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!
我不是专家,但是当你写0 3时,你是说0。3吗?我们通常不会用逗号来表示小数点!
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.
在深入研究更高级的东西之前,试着花点时间熟悉python本身和编程。