Interesting Math Problem

Chuckk Hubbard badmuthahubbard at gmail.com
Thu Jun 5 10:55:41 CEST 2008


On Thu, Jun 5, 2008 at 11:52 AM, Chuckk Hubbard
<badmuthahubbard at gmail.com> wrote:
> On Wed, Jun 4, 2008 at 11:03 AM, BEES INC <bees.inc at gmail.com> wrote:
>
>> My Solution (in Python):
>>
>> # round to one decimal place and
>> # separate into whole and fractional parts
>> parts = str(round(star_sum/num_raters, 1)).split('.')
>> whole = int(parts[0])
>> frac = int(parts[1])
>> if frac < 3:
>> ___frac = 0
>> elif frac > 7:
>> ___frac = 0
>> ___whole += 1
>> else:
>> ___frac = 5
>> # recombine for a star rating rounded to the half
>> stars = float(str(whole)+'.'+str(frac))
>
> def roundstars(invalue):
>    inv *= 2
>    inv += .5
>    return float(int(inv))/2
>
> seems to work for me.

My mistake:

a = (star_sum/num_raters) * 2
a += .5
stars = float(int(a))/2

-Chuckk


-- 
http://www.badmuthahubbard.com



More information about the Python-list mailing list