0
Help fill the gap
list = [1,2,3,4] if ___ (list) % 2 ==0: print(list[0])
5 Answers
+ 3
You sure that code is correct?
If you wanna print even numbers in the list, the code should be something like:
myList = [1,2,3,4]
for n in myList:
if n % 2 == 0:
print(n)
+ 2
Is this a question in the course, or an 'anything that makes this work' test? Both sum() and len() are perfectly valid for the existing code, and they both (improperly) succeed but throw an IndexException when the list is empty.
Probably not important, just curious.
0
It was necessary to write Len.
0
It depends on what the code should do.
And btw, list is a built-in method. That's not good to override it as a variable.
0
You mean len.