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 108 discussion

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

What is the expected behavior of the following code?

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

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
seaverick
2 months, 4 weeks ago
Selected Answer: 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
upvoted 2 times
...
kstr
5 months, 1 week ago
The answer is right B tested
upvoted 1 times
...
Janpcap123
7 months, 3 weeks ago
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'
upvoted 1 times
...
andr3
1 year, 1 month ago
Selected Answer: 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]
upvoted 4 times
...
Nenggg
1 year, 4 months ago
If there is no "]" after the for loop then, C would be the answer. Otherwise, "]" cause the error and answer will be B
upvoted 1 times
...
rotimislaw
1 year, 5 months ago
Selected Answer: 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
upvoted 2 times
...
pablohm83
1 year, 6 months ago
Selected Answer: C
C. I suppose there is a typo error in the transcription
upvoted 1 times
...
macxsz
1 year, 11 months ago
Selected Answer: B
B. the code is erroneous and it will not execute
upvoted 2 times
...
rocky48
2 years ago
Selected Answer: 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]
upvoted 3 times
...
sadako11
2 years, 2 months ago
Syntax Error. There is an unmatched extra bracket. (maybe at typo who knows?) Without it the answer is [3,1]
upvoted 4 times
rocky48
2 years ago
>>> 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]
upvoted 2 times
...
...
DTL001
2 years, 4 months ago
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]
upvoted 1 times
...
DTL001
2 years, 4 months ago
it outputs [3, 1]
upvoted 1 times
...
kungtabumi
2 years, 6 months ago
right answer is C
upvoted 2 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 ...