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

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

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 (?) , you can switch to a simple comment.
Switch to a voting comment New
seaverick
2 months, 3 weeks 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
11 months ago
Selected Answer: A
Exam has no typo errors. Output is [4,2] Answer is: A
upvoted 4 times
...
gekkehenk
1 year 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, 1 month ago
can somebody who took exam already confirm if in real exam code is erroneous ?
upvoted 1 times
Rizos
1 year, 1 month ago
There are no typos or indentation issues in the real exam.
upvoted 3 times
...
...
besha
1 year, 9 months ago
if ] in the correct place, then the correct answer would be A
upvoted 3 times
...
angelika_az
1 year, 10 months ago
SyntaxError, - there is no else statement
upvoted 1 times
...
macxsz
1 year, 11 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 ...