[Tutor] Problems when displaying numbers

Patty patriciap.gu at gmail.com
Thu Apr 13 13:56:36 CEST 2006


Hi:


>it would be really helpful to see an example of 'result' before and
>after the call to calc_numbers() as well as the code for calc_numbers if 
>possible. 


 
An example of result before the call to calc_numbers is: [50L, -1, 1, -1]
an example after the call is: [50L, 25, ' ', 25]
 
the code:
def calc_numbers(alist):

    sum = 0
    count = 0

    for li in alist:
        # in the database, -1 is unspecified and 1 is null
        if li >= 0 and li != 1:
            sum = sum + int(li)
        if li == -1:
            count = count + 1

    temp = 100 - sum
    if count != 0:
        number = temp/count
    else:
        number = temp

    for li, pos in enumerate(alist):
        if pos == -1:
            alist[li] = number
        elif pos == 1:
            alist[li] = ''


    return alist


 

Thanks,

Patricia




More information about the Tutor mailing list