【问题标题】:"unsupported operand type(s) for ** or pow(): 'list' and 'int'"“** 或 pow() 不支持的操作数类型:'list' 和 'int'”
【发布时间】:2017-03-27 13:01:40
【问题描述】:

我正在为我的大学期末作业制定一个计划。这是一种计算无人机手臂厚度的算法。 我在 SageMath 上做了表达式,用 Python 开发

import math
import matplotlib.pyplot as plt
import pylab 

F=float((2*9.81)/4)
S=float(1.5) #coeficiente de segurança
Tensrup=float(4.1575e+7) #Tensão de ruptura
T=Tensrup/S  #Tensão adm (que foi multiplicada por 1.1)
r=float(0.75*10**-3)  #raio interior
b=range(1, 1000)
L=[x*10**-3 for x in b] #*10**⁻3 is a unity conversion
R=[]
for l in L:
    R.append(1/10000*math.sqrt(1/3)*math.sqrt((75000000*(6050000000/98695877281*F**2*L**2*S**2/T**2 + 1/37010953980375000000000*math.sqrt(5147226562500000000000000000000000000000000*F**4*L**4*S**4 + 9740876192266211952961/3*T**4)/T**2)**(2/3) - 1)/(6050000000/98695877281*F**2*L**2*S**2/T**2 + 1/37010953980375000000000*math.sqrt(5147226562500000000000000000000000000000000*F**4*L**4*S**4 + 9740876192266211952961/3*T**4)/T**2)**(1/3)) + 1/2*math.sqrt(3300000000/314159*math.sqrt(1/3)*F*L*S/(T*math.sqrt((75000000*(6050000000/98695877281*F**2*L**2*S**2/T**2 + 1/37010953980375000000000*math.sqrt(5147226562500000000000000000000000000000000*F**4*L**4*S**4 + 9740876192266211952961/3*T**4)/T**2)**(2/3) - 1)/(6050000000/98695877281*F**2*L**2*S**2/T**2 + 1/37010953980375000000000*math.sqrt(5147226562500000000000000000000000000000000*F**4*L**4*S**4 + 9740876192266211952961/3*T**4)/T**2)**(1/3))) - (6050000000/98695877281*F**2*L**2*S**2/T**2 + 1/37010953980375000000000*math.sqrt(5147226562500000000000000000000000000000000*F**4*L**4*S**4 + 9740876192266211952961/3*T**4)/T**2)**(1/3) + 1/75000000/(6050000000/98695877281*F**2*L**2*S**2/T**2 + 1/37010953980375000000000*math.sqrt(5147226562500000000000000000000000000000000*F**4*L**4*S**4 + 9740876192266211952961/3*T**4)/T**2)**(1/3)))
plot = plt.figure(1)
plt.plot(L,R)
plt.ylabel("Raio exterior (m)")
plt.xlabel("Largura do braço (m)")
plt.title("Dimensionamento dos braços",  fontweight='bold')
plt.grid(True)
plt.tight_layout()

pylab.show()

我想创建一个在 1 和 1000 之间变化的长度 (L)(然后我乘以 10⁻3 以转换为毫米)并逐点计算以查看手臂的最佳长度。 当我运行它时,我收到此错误

The debugged program raised the exception unhandled TypeError
"unsupported operand type(s) for ** or pow(): 'list' and 'int'" File:
/home/zanetti/Documents/Python/DRone.py, Line: 14

我是一名爱好者和代码初学者。我已经用列表和数组尝试了一些东西,但事实是我几乎什么都不懂=/

【问题讨论】:

    标签: list python-3.x int


    【解决方案1】:

    您将L 的元素循环为l,但您在大计算行中使用L,而您应该使用l

    这意味着解释器在某些时候偶然发现了L**2,这是一个提升到 2 次方的列表,在 python 中没有任何意义。

    建议:避免使用相同名称且仅因大小写而异的变量。改进变量的命名将为您省去很多麻烦。

    【讨论】:

    • +1 最后一部分。严重地。命名很困难,但任何东西都比单字母名称好(除非我可能会编写通用的、功能性的 HOF)。具有描述性!
    • 谢谢。在回答“简单”的问题时,我会尝试添加一些内容。
    猜你喜欢
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2018-02-05
    相关资源
    最近更新 更多