0

What am I doing wrong in this exercise??

Hi, The task is to calculate the middle index of a given list called 'items'. I believe my code (shown below) does exactly what it's supposed to do, but somehow the code verifier in the app seems to disagree and doesn't leave me any clues as to what the problem is 🤷🏻‍♂️ Any hints will be appreciated. middle_index = len(items)//2

27th Dec 2020, 10:12 PM
Hans Thorsager
Hans Thorsager - avatar
3 ответов
+ 1
Abhay, Hans Thorsager, if we have list of length 7 the code gives the middle index right => 0, 1, 2, 3(middle index), 4, 5, 6. But what if you have list with length even number. Then the middle elements are two => 0, 1 (middle index) , 2 (middle index) , 3. For reference look here: https://discuss.codecademy.com/t/how-can-i-get-the-index-of-the-middle-element/377349
27th Dec 2020, 10:31 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
TheWh¡teCat 🇧🇬 ty for correcting me ,I believe the list length should be odd only otherwise for sure it won't give a middle index for even length of list
27th Dec 2020, 10:35 PM
Abhay
Abhay - avatar
0
Abhay , I think that's not the full description of the task. So it is hard to guess what exactly could make the solution. In the link I posted there is such case with even length of the list => then we have two middle elements.
27th Dec 2020, 10:38 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar