0
Python Module 3 Quiz Question 4
Fill in the blanks to print the first element of the list, if it contains even number of elements. list = [1, 2, 3, 4] if (list) % 2 == 0: print(list[0]) Question: What is supposed to go between the if and the '(list)'?
6 Respostas
+ 3
"len" - len means the length of the list, string, tuple, sets. It is the number of elements in a data structure.
What "if it contains even number of elements" means is the number of elements in the list should be even number. There are 4 elements which are [1,2,3,4].
And 4 is even, means the condition will be True, then prints the first element, list[0].
If in case the number of elements in a list is 5 [1,2,3,4,5], the condition will be False. Thus, the program wont print list[0]
But Next time, always check the comment section if youre having difficulties in quizzes. People explain it there.
+ 1
Struggled with this question for a couple of hours. I agree that the wording is difficult to understand what is being asked as it seems grammatically incorrect as well.
0
Thanks for your help I got the question right. However there was not a comment section in the module 3 quiz.
0
Thanks for providing information about the solution. This problem is not worded as well as it could be. I thought it wanted us to print the value inside the list if it was even. It wasn't worded well enough for us to know that they actually meant "if the list has an even number of elements, print the first element in the list".
Pretty confusing for no reason imo. Thanks for info.
0
which of the following sentence are true?(select two answers)
nums={1,2,3}
vals=nums{-1:-2}
1- nums and vals are two different lists.
2-nums and vals are of the same length.
3-vals is longer than nums
4-nums is longer than vals.
0
1. len
2. :
3. list