PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 118


What is the expected behavior of the following code?

Show Answer
Correct Answer: D

D

Discussion

7 comments
Sign in to comment
kontraOption: A
May 24, 2023

Exam has no typo errors. Output is [4,2] Answer is: A

beshaOption: A
Jul 4, 2022

if ] in the correct place, then the correct answer would be A

gekkehenkOption: D
Mar 28, 2023

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]

macxszOption: D
May 4, 2022

D. the code is erroneous and it will not execute

angelika_azOption: D
Jun 1, 2022

SyntaxError, - there is no else statement

andr3
Mar 21, 2023

can somebody who took exam already confirm if in real exam code is erroneous ?

Rizos
Mar 21, 2023

There are no typos or indentation issues in the real exam.

seaverickOption: D
Jan 27, 2024

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