lundi 16 décembre 2019

A code that gives the mode of the data (shouldn't use functions available under the statistics)

I am trying to write a code that gives the mode of the data. And I shouldn't use functions available under the statistics module but I can use built-in functions such as max,min,sum,etc.

list1 = [1,2,3,4,5,4,3,2,1,2,3,3,4,2,1,3,2,1,3,5]
time=0
freq1=0
freq2=0
freq3=0
freq4=0
freq5=0
for i in list1:
    if list1[i]==1:
        time+=time
        freq1=time
    elif list1[i]==2:
        time+=time
        freq2=time
    elif list1[i]==3:
        time+=time
        freq3=time
    elif list1[i]==4:
        time+=time
        freq4=time
    elif list1[i]==5:
        time+=time
        freq5=time
list2=[freq1,freq2,freq3,freq4,freq5]
print(max(list2))

Here is what I get

0
>>> 

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire