What is the expected behavior of the following code?
What is the expected behavior of the following code?
D
Exam has no typo errors. Output is [4,2] Answer is: A
Answer is indeed D, due to the ] before the if statement. If this bracket wouldnt be there, the result would be [4, 2]. my_list = [i for i in range(5,0,-1)] m = [my_list[i] for i in range(5) if my_list[i] % 2 == 0] print(m) [4, 2]
if ] in the correct place, then the correct answer would be A
my_list = [i for i in range(5,0,-1)] m=[my_list[i] for i in range(5)] if my_list[i]%2==0 print(m) #output SyntaxError: expected 'else' after 'if' expression Ans is D
can somebody who took exam already confirm if in real exam code is erroneous ?
There are no typos or indentation issues in the real exam.
SyntaxError, - there is no else statement
D. the code is erroneous and it will not execute