Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 118 discussion

Actual exam question from Python Institute's PCAP
Question #: 118
Topic #: 1
[All PCAP Questions]

What is the expected behavior of the following code?

  • A. it outputs [4, 2]
  • B. it outputs [2, 4]
  • C. it outputs [0, 1, 2, 3, 4]
  • D. the code is erroneous and it will not execute
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
seaverick
10 months ago
Selected Answer: D
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
upvoted 1 times
...
kontra
1 year, 6 months ago
Selected Answer: A
Exam has no typo errors. Output is [4,2] Answer is: A
upvoted 4 times
...
gekkehenk
1 year, 8 months ago
Selected Answer: D
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]
upvoted 3 times
...
andr3
1 year, 8 months ago
can somebody who took exam already confirm if in real exam code is erroneous ?
upvoted 1 times
Rizos
1 year, 8 months ago
There are no typos or indentation issues in the real exam.
upvoted 3 times
...
...
besha
2 years, 4 months ago
if ] in the correct place, then the correct answer would be A
upvoted 3 times
...
angelika_az
2 years, 6 months ago
SyntaxError, - there is no else statement
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: D
D. the code is erroneous and it will not execute
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...