0
How do we solve exercice 26.4 the middle element?
3rd Section, following List function lesson I have to find the middle element Using len() What I did: items=[1,2,3,8,5,4,7] long=len(items) middle=long//2 index=items[middle] print(index) Cant debug
3 odpowiedzi
+ 5
You need to print index as output.  Not actual value. So print middle variable
0
list=[1,2,3,4,5,6,7,8,9,0]
print('My list is: ',list)
n=len(list)
if(not n%2==0):
    p=n//2
    p=int(p)
    print('Items entered in list are odd')
    print('Middle element is: ',list[p])
else:
    q=int(n/2)
    r=list[q]
    s=list[q-1]
    avg=(r+s)/2
    print('Items entered in list are even')
    print('Average of numbers is: ',avg)
in this program if items in list are odd then it returns the middle element and if items in list are even then it returns the average value of two elements



