import math
def getBestLoc(lst):
if len(lst) % 2 == 0:
#bestLoc = (lst((len(lst)/2) + lst(len(lst)/2)-1))/2
bestLoc = ((lst[len(lst)]//2) + (lst[len(lst)/2]-1)) // 2
else:
bestLoc = lst(len(lst)//2)
sumOfDistances(lst, bestLoc)
return bestLoc
def sumOfDistances(lst, bestLoc):
total = 0
for i in lst:
total += math.abs(bestLoc - i)
return total
def main():
lst = [10, 15, 30, 200]
lst.sort()
print(lst)
getBestLoc(lst)
main()
I got this error:
Traceback (most recent call last):
File "C:\Users\NAME\Desktop\storeLocation.py", line 32, in <module>
main()
File "C:\Users\NAME\Desktop\storeLocation.py", line 30, in main
getBestLoc(lst)
File "C:\Users\NAME\Desktop\storeLocation.py", line 14, in getBestLoc
bestLoc = ((lst[len(lst)]//2) + (lst[len(lst)/2]-1)) // 2
IndexError: list index out of range
I don't know what I did wrong. It is saying, IndexError: list index out of range, I don't know what that means. It is my lab homework. Trying to figure this issue out. Any help? Thanks.