[Tutor] toggle through a list

j mercedes jrodriguo at hotmail.com
Thu Apr 2 01:59:38 CEST 2009


Hi, I have problem here...I am writing a program but I am getting stucked at how to solve the mode of a series of numbers...any ideas???following is the program:def mode(data):    num=0    count=0    mx=0    mode=0    for i in data:        if num!=data[i]:            num=data[i]            count=count+1        else :            count=count+1    if count>mx:        mx=count        mode=num    print 'The mode is: ',mode    def median(lst):    x=len(data)    y=x/2    print 'The median is: ',data[y]def getlst():    num=[]    while True:        s=raw_input('please enter a series of number to evaluate')        if s=='':break        num.append(eval(s))    return numdef avg(y):   sum(y)   print'the average is: ', sum/len(y)data=getlst()median(data)avg(data)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090401/26788ff2/attachment.htm>


More information about the Tutor mailing list