Exam PCAP All QuestionsBrowse all questions from this exam
Question 108

What is the expected behavior of the following code?

    Correct Answer: C

    B

Discussion
andr3Option: C

In [89]: mylist = [ i for i in range(5)] In [90]: mylist Out[90]: [0, 1, 2, 3, 4] In [91]: m = [mylist[i] for i in range (4,0,-1) if mylist[i] % 2!=0 ] In [92]: m Out[92]: [3, 1]

sadako11Option: C

Syntax Error. There is an unmatched extra bracket. (maybe at typo who knows?) Without it the answer is [3,1]

rocky48

>>> my_list = [i for i in range(5)] >>> m = [my_list[i] for i in range(4,0,-1) if my_list[i] % 2 != 0] >>> print(m) [3, 1]

rocky48Option: C

>>> my_list = [i for i in range(5)] >>> m = [my_list[i] for i in range(4,0,-1) if my_list[i] % 2 != 0] >>> print(m) [3, 1]

seaverickOption: B

my_list = [i for i in range(5)] m = [my_list[i] for i in range(4,0,-1)] if my_list[i] %2 != 0] print(m) output -> SyntaxError: unmatched ']' Ans -> B

rotimislawOption: B

B: There's an ']' before 'if' statement so the code is erroneous If that wasn't the case, the [3, 1] would be printed

macxszOption: B

B. the code is erroneous and it will not execute

kungtabumiOption: C

right answer is C

kstrOption: B

The answer is right B tested

Janpcap123Option: B

Based on the exact code presented the correct answer is B, if you remove the ']' from the code obviously the answer becomes [3,1] BUT the fact is ']' exists in the code so you must select B as the correct answer and nor speculate on 'what if's'

NengggOption: B

If there is no "]" after the for loop then, C would be the answer. Otherwise, "]" cause the error and answer will be B

pablohm83Option: C

C. I suppose there is a typo error in the transcription

DTL001Option: C

Answer is C my_list = [i for i in range(5)] m = [my_list[i] for i in range(4,0,-1) if my_list[i] % 2 != 0 ] print(m) [3,1]

DTL001Option: C

it outputs [3, 1]