Output different in VIsual Studio and Codeacademy


#1

The code below gives different output when you run in Visual studio and Codeacademy. What is the issue?

def median(lst):
val=len(lst)
st=sorted(lst)
if val % 2==0:
index1=int(val/2)-1
print (index1)
index2=int((val/2)+1)-1
print (index2)
median=(st[index1]+st[index2])/2
elif val % 2 !=0:
index=int((val+1)/2)-1
print (index)
median = st[index]
print (median)
return median

median([4,5,5,4])


#2

From what I can make out from this unformatted code, your indexes are incorrect.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.