0

I'm trying to calculate something in a function with numbers from an imported list.

def calculate_powers(velocities_list):
    power_list = []
    for i in velocities_list:
        power = 8/27 * 1.225 * i * 8659
        power_list.append(power)
    print(power_list)

However, I get the following error:

File "C:\Users\Omistaja\PycharmProjects\7_1\wind_turbine.py", line 6, in calculate_powers
    power = 8/27 * 1.225 * i * 8659
TypeError: can't multiply sequence by non-int of type 'float'

What to do?

K K
  • 41
  • 5
  • 2
    It seems like `velocities_list` is list of lists, not list of numbers as you think – Drecker Nov 09 '21 at 10:42
  • 1
    Please, provide [mre]. Edit your question to include sample `velocities_list`. – buran Nov 09 '21 at 10:42
  • Does this answer your question? [Why do I get TypeError: can't multiply sequence by non-int of type 'float'?](https://stackoverflow.com/questions/485789/why-do-i-get-typeerror-cant-multiply-sequence-by-non-int-of-type-float) – Ocaso Protal Nov 09 '21 at 10:43

2 Answers2

1

try this :

def calculate_powers(velocities_list):
    power_list = []
    for i in velocities_list:
        power = float(8/27) * 1.225 * float(i) * float(8659)
        power_list.append(power)
    print(power_list)

itjuba
  • 518
  • 4
  • 23
1

your variable 'i' is probably string, you need to cenvert it to number(float or int,..)

power = 8/27 * 1.225 * float(i) * 8659

can you provide example of your velocities_list?

ncica
  • 7,015
  • 1
  • 15
  • 37