Convert int to float

Dan Bishop danb_83 at yahoo.com
Sat Mar 15 23:48:58 CET 2008


On Mar 15, 4:43 pm, Guido van Brakel <guidovb1 at invalid> wrote:
> Hello
>
> I have this now:
>
> > def gem(a):
> >     g = sum(a) / len(a)
> >     return g
>
> > print gem([1,2,3,4])
> > print gem([1,10,100,1000])
> > print gem([1,-2,3,-4,5])
>
> It now gives a int, but i would like to see floats. How can integrate
> that into the function?

If you add "from __future__ import division" at the top of the file,
division will work properly.



More information about the Python-list mailing list