【发布时间】:2018-09-01 17:15:22
【问题描述】:
我正在尝试获取每个时间值的向量和度数的值,但我遇到了这个错误:
TypeError: +: 'int' 和 'tuple' 的操作数类型不受支持
如果我遵循回溯,我会得到 x = -0,3*(t**2)+(7,2*t)+28,但它为什么是 int = tuple?
追溯:
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
代码:
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)
【问题讨论】:
-
Python 使用点来表示小数点,而不是逗号。
标签: python function return tuples