Convert int to float

sturlamolden sturlamolden at yahoo.no
Sat Mar 15 17:45:43 EDT 2008


On 15 Mar, 22:43, Guido van Brakel <guidovb1 at invalid> wrote:

> > def gem(a):
> >     g = sum(a) / len(a)
> >     return g

> It now gives a int, but i would like to see floats. How can integrate
> that into the function?

You get an int because you are doing integer division. Cast one int to
float.

def gem(a):
   g = sum(a) / float(len(a))
   return g






More information about the Python-list mailing list