I'm having trouble with some python code (simple things). This goes to the point where I hope that if I click on the run button, it might work ...
Here is the code:
Data = [1, 2, 3, 4, 5]
Frequency = [1, 2, 3, 3, 1]
def mode(data1, frequency1):
mode = [0]
count = 0
while count != len(frequency1):
if frequency1[count] > mode[0]:
mode = data1[count]
elif frequency1[count] == mode:
mode = [mode, data1[count]]
count +=1
return mode
mode = mode(Data, Frequency)
print(mode)
It returns:
if Frequency[0] > mode[0]:
TypeError: 'int' object is not subscriptable
I looked at another question and answer, but he looked for me. Where am I going wrong!
Edit: I know that there are modules that you can import to find the average value, but I want to do this without importing anything.
Edit: now all the code. If I do not make the mode variable a list, this will be fine until there are two modes.
source
share