PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 108


What is the expected behavior of the following code?

Show Answer
Correct Answer: B

B

Discussion

13 comments
Sign in to comment
sadako11Option: C
Feb 15, 2022

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

rocky48
Apr 23, 2022

>>> 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]

andr3Option: C
Mar 25, 2023

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]

rocky48Option: C
Apr 23, 2022

>>> 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]

kungtabumiOption: C
Oct 16, 2021

right answer is C

macxszOption: B
May 4, 2022

B. the code is erroneous and it will not execute

rotimislawOption: B
Nov 15, 2022

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

seaverickOption: B
Jan 27, 2024

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

DTL001Option: C
Dec 20, 2021

it outputs [3, 1]

DTL001Option: C
Dec 20, 2021

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]

pablohm83Option: C
Oct 5, 2022

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

NengggOption: B
Dec 11, 2022

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

Janpcap123Option: B
Sep 1, 2023

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'

kstrOption: B
Nov 16, 2023

The answer is right B tested