* 不支持的操作数类型:'float' 和 'decimal'
unsupported operand types for * : 'float' and 'decimal'
for a in range(0,size):
et = 0.0023*ralist[rows[a][2]] * ( 0.5*(rows[a][3] + rows[a][4]) + 17.8 ) * ( rows[a][3] - rows[a][4])**(0.5)
eto_values.insert(a,et)
当我尝试 运行 代码时,出现以下错误:
unsupported operand types for * : 'float' and 'decimal'
我也尝试过使用 decimal.Decimal()
函数。有人可以告诉我如何清除此错误吗?
您不能乘以或设计 float
和 decimal.Decimal()
类型,我建议乘以 Decimal('0.0023')
和 Decimal('0.5')
:
for a in range(0,size)
et = Decimal('0.0023')*ralist[rows[a][2]] * ( Decimal('0.5')*(rows[a][3] + rows[a][4]) + 17.8 ) * ( rows[a][3] - rows[a][4])**(0.5)
eto_values.insert(a,et)
>>> from decimal import *
>>> Decimal(1.2) * Decimal(3.4)
Decimal('4.079999999999999742428258287')
>>> Decimal(1.2) * 3.4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'
for a in range(0,size):
et = 0.0023*ralist[rows[a][2]] * ( 0.5*(rows[a][3] + rows[a][4]) + 17.8 ) * ( rows[a][3] - rows[a][4])**(0.5)
eto_values.insert(a,et)
当我尝试 运行 代码时,出现以下错误:
unsupported operand types for * : 'float' and 'decimal'
我也尝试过使用 decimal.Decimal()
函数。有人可以告诉我如何清除此错误吗?
您不能乘以或设计 float
和 decimal.Decimal()
类型,我建议乘以 Decimal('0.0023')
和 Decimal('0.5')
:
for a in range(0,size)
et = Decimal('0.0023')*ralist[rows[a][2]] * ( Decimal('0.5')*(rows[a][3] + rows[a][4]) + 17.8 ) * ( rows[a][3] - rows[a][4])**(0.5)
eto_values.insert(a,et)
>>> from decimal import *
>>> Decimal(1.2) * Decimal(3.4)
Decimal('4.079999999999999742428258287')
>>> Decimal(1.2) * 3.4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'