0
List Functions Code Coach Exercise
In this exercise, I have to find the number that is in the middle of the list. Here is my code items = [2, 4, 6, 8, 10, 12, 14] #your code goes here numbers = len(items) half = numbers //2 print(items[half]) I got the wrong results.
5 Antworten
+ 6
#print statement has to be on the same indentation level:
items = [2, 4, 6, 8, 10, 12, 14]
#your code goes here
numbers = len(items)
half = numbers //2
print(items[half])
Edit:
Az Far oh! got it. You have to print its index.
Add this
print(half)
0
Given a list, calculate the middle element's index.
Hint given: 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 (//).
0
Ohh! I get it now. Thank u very much 😁
0
check out this:
Both ways are correct
items = [2, 4, 6, 8, 10, 12, 14]
middle = len(items)//2
print(middle)
or
items = [2, 4, 6, 8, 10, 12, 14]
print(len(items)//2)
- 1
I fixed the indentation but somehow my answer is still wrong