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\PycharmProjects7円_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?
2 Answers 2
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)
Sign up to request clarification or add additional context in comments.
Comments
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?
answered Nov 9, 2021 at 10:48
ncica
7,2161 gold badge19 silver badges41 bronze badges
Comments
lang-py
velocities_listis list of lists, not list of numbers as you thinkvelocities_list.