How about adding rational fraction to Python?
Paul Rubin
http
Tue Feb 26 23:55:14 EST 2008
More information about the Python-list mailing list
Tue Feb 26 23:55:14 EST 2008
- Previous message (by thread): How about adding rational fraction to Python?
- Next message (by thread): How about adding rational fraction to Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Mark Dickinson <dickinsm at gmail.com> writes: > def mean(number_list): > return sum(number_list)/len(number_list) > > If you pass a list of floats, complex numbers, Fractions, or Decimal > instances to mean() then it'll work just fine. But if you pass > a list of ints or longs, it'll silently return the wrong result. So use: return sum(number_list) / float(len(number_list)) That makes it somewhat more explicit what you want. Otherwise I wouldn't be so sure the integer result is "wrong".
- Previous message (by thread): How about adding rational fraction to Python?
- Next message (by thread): How about adding rational fraction to Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list