简体   繁体   中英

unsupported operand type(s) for ** or pow(): 'list' and 'int' error

i have to calculate "a" with this formula:

在此处输入图像描述

The variable "I" is a list, I tried this way but I get this error:

a = (675 * 10**-9 * (I**3)) - (771 * 10**-7 * (I**2)) + (1792 * 10**-5 * I) + 0.49239

TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'    

Can somebody help me?

Here is one way of doing it using a List Comprehension:

I = [1,2,3,4,5]
a = [(675 * 10**-9 * (i**3)) - (771 * 10**-7 * (i**2)) + (1792 * 10**-5 * i + 0.49239) for i in I]
print (a)

This prints the following answer:

[0.510233575, 0.5279269999999999, 0.545474325, 0.5628795999999999, 0.5801468750000001]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM