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 :)

Upvotes: 0

Views: 2297

Answers (1)

abc
abc

Reputation: 11929

You are multiplying a tuple with an integer at the beginning. The result is a tuple and you get an error when dividing it with an 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

Upvotes: 3

Related Questions