+ 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)])
4 ответов
+ 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
+ 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
+ 1
FunOfCoding thank you so much for this help 🙂🙏It works
0
items = [2, 4, 6, 8, 10, 12, 14]
#your code goes here
a=len(items)
print(a//2)