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.

22nd Dec 2020, 3:42 AM
Az Far
Az Far - avatar
5 ответов
+ 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)
22nd Dec 2020, 5:21 AM
Simba
Simba - avatar
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 (//).
22nd Dec 2020, 5:17 AM
Az Far
Az Far - avatar
0
Ohh! I get it now. Thank u very much 😁
22nd Dec 2020, 5:23 AM
Az Far
Az Far - avatar
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)
27th Jan 2023, 5:08 AM
Himasha Nethmini
Himasha Nethmini - avatar
- 1
I fixed the indentation but somehow my answer is still wrong
22nd Dec 2020, 4:25 AM
Az Far
Az Far - avatar