[Tutor] Mathematical operations on a list

JUDE EJEPU ejepujude at gmail.com
Wed Oct 20 16:59:21 EDT 2021


Sir,
I created a function to calculate a variable G
def gfactor(dist,electro):
       G = pie_value() * (dist**2 - electro**2)/(2*electro)
    return G

So I tried an example and it worked.
gFactor(10,2) ----> 75.408
However, when I passed a list of arguments,:
x = [1, 2, 3]
y = [0.5, 0.5, 1]
gFactor(x,y), I got an error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-66124c985163> in <module>
----> 1 gFactor(x,y)

<ipython-input-3-9e0effe1021d> in gFactor(dist, electro)
     12     Output: ---> float
     13     """
---> 14     G = 3.142 * (dist**2 - electro**2)/(2*electro)
     15     return G

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


Please, how may I correct the function?

Thank you.


More information about the Tutor mailing list