【问题标题】:TypeError: unsupported operand type(s) for +: 'int' and 'tuple'类型错误:+ 不支持的操作数类型:“int”和“tuple”
【发布时间】: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


【解决方案1】:

我不是专家,但是当您写 0,3 时,您的意思是 0.3 吗? 我们通常不会在数字中使用逗号作为小数点!

这就是我认为您收到上述错误的原因,因此请将逗号更改为点并重试。

在深入研究更高级的东西之前,尝试花时间熟悉 Python 本身和编程。

【讨论】:

  • 谢谢你的回答,我很粗心,因为我试图为物理课做一个情节,而在我的国家我们用逗号写小数点,所以我最终输入了公式并没有甚至没有注意到。
  • 我总是犯一些有趣的错误,尤其是在我开始从事开发工作的时候。如果您接受答案,那就太好了。
  • 我什至不得不编辑我最后的评论 3 次以删除拼写错误:D
  • 只想说最后一切都很好:graph
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-17
  • 1970-01-01
  • 1970-01-01
  • 2013-10-04
  • 2021-06-16
  • 2014-06-16
  • 2014-03-16
相关资源
最近更新 更多