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 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: C 🗳️

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: 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
1 year ago
The answer is right B tested
upvoted 1 times
...
Janpcap123
1 year, 2 months 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, 8 months 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, 11 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
2 years 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
2 years, 1 month ago
Selected Answer: C
C. I suppose there is a typo error in the transcription
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: B
B. the code is erroneous and it will not execute
upvoted 2 times
...
rocky48
2 years, 7 months 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, 9 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, 7 months 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, 11 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, 11 months ago
it outputs [3, 1]
upvoted 1 times
...
kungtabumi
3 years, 1 month 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 ...