Help fill the gap | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Help fill the gap

list = [1,2,3,4] if ___ (list) % 2 ==0: print(list[0])

21st Nov 2016, 3:04 PM
ŠšŠ¾Ń€Š°Š»ŠøŠ½Š° Š“Ń€ŠøŠ½
ŠšŠ¾Ń€Š°Š»ŠøŠ½Š° Š“Ń€ŠøŠ½ - avatar
5 Respostas
+ 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)
21st Nov 2016, 3:26 PM
Alireza M
Alireza M - avatar
+ 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.
22nd Nov 2016, 12:06 AM
Kirk Schafer
Kirk Schafer - avatar
0
It was necessary to write Len.
21st Nov 2016, 4:11 PM
ŠšŠ¾Ń€Š°Š»ŠøŠ½Š° Š“Ń€ŠøŠ½
ŠšŠ¾Ń€Š°Š»ŠøŠ½Š° Š“Ń€ŠøŠ½ - avatar
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.
21st Nov 2016, 4:13 PM
donkeyhot
donkeyhot - avatar
0
You mean len.
21st Nov 2016, 4:26 PM
donkeyhot
donkeyhot - avatar