+ 2

Whats wrong in this program?I got error in Test case it's locked I can't see

Given a list, calculate the middle element's index. You can use the len() function to get the number of elements in the list and then floor divide it by 2 using two slashes (//). items = [2, 4, 6, 8, 10, 12, 14] #your code goes here print(items[int(len(items)//2)])

6th Jan 2021, 8:01 PM
Priyankar Ghosh
Priyankar Ghosh - avatar
4 Respuestas
+ 10
You did print(items[int(len(items)//2)]) instead of print(int(len(items)//2)). What I did is removing items[ ] because then it will look at the middle of the list and print the value of that list. for example: code: list = [1,2,3] print(list[1]) output: 2
6th Jan 2021, 8:07 PM
Baspberry
+ 2
items = [2, 4, 6, 8, 10, 12, 14] #your code goes here a=len(items) print(a//2) i used this and it worked
17th Jan 2022, 11:53 AM
lost king
lost king - avatar
+ 1
FunOfCoding thank you so much for this help 🙂🙏It works
6th Jan 2021, 8:11 PM
Priyankar Ghosh
Priyankar Ghosh - avatar
0
items = [2, 4, 6, 8, 10, 12, 14] #your code goes here a=len(items) print(a//2)
15th Nov 2022, 11:37 AM
Pooja Patel
Pooja Patel - avatar