[英]TypeError: unsupported operand type(s) for /: 'tuple' and 'int' ---don't understand the error
I'm trying to run a code only I don't understand this error:我试图运行一个代码,但我不明白这个错误:
if AC_energy / pow == 1:
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
The piece of code:这段代码:
Power = (5, 10, 15, 20)
for pow in Power:
for Hours in range(1, 6):
AC_energy = Power * Hours
print(AC_energy)
if AC_energy / pow == 1:
Rack_energy = 230
else:
Rack_energy = 288
Nbr_rack = ((AC_energy *(1 + 0.2)) *1000) / Rack_energy
Energy = ((Rack_energy * Nbr_rack)/ 1000)* 0.95
Thank you for your help:)谢谢您的帮助:)
You are multiplying a tuple with an integer at the beginning.您在开始时将一个元组与 integer 相乘。 The result is a tuple and you get an error when dividing it with an integer.
结果是一个元组,在将其与 integer 相除时会出现错误。
>>> (5, 10, 15, 20) * 6
(5, 10, 15, 20, 5, 10, 15, 20, 5, 10, 15, 20, 5, 10, 15, 20, 5, 10, 15, 20, 5, 10, 15, 20)
What you might want to do is to change the line您可能想要做的是更改线路
AC_energy = Power * Hours
with和
AC_energy = pow * Hours
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.