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

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

What is the expected output of the following code?

  • A. 2
  • B. The code will cause a runtime exception
  • C. 1
  • D. 3
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
Avidulam
Highly Voted 4 years, 8 months ago
Length will be 3, the answer is D
upvoted 16 times
prak
4 years, 6 months ago
1st is invalid parameter, so the code will issue syntax error.
upvoted 10 times
...
jasonvolta
4 years, 6 months ago
its a bit tricky this one. lst or 1st?
upvoted 2 times
...
myname80
4 years, 5 months ago
there is a space between two equal signs, so it is an error
upvoted 2 times
catarata
3 years, 2 months ago
There is a space in the range function too so... we'll never know
upvoted 1 times
...
...
...
wprogrammer
Highly Voted 3 years, 9 months ago
The answer B is OK because the name of the variable "1st" is incorrect. Variables names can contain numbers but not at the begin.
upvoted 13 times
...
julmarcas
Most Recent 8 months, 2 weeks ago
Selected Answer: D
>>> lst = [x for x in range(5)] >>> lst [0, 1, 2, 3, 4] >>> lst = list(filter(lambda x: x % 2 == 0, lst)) >>> lst [0, 2, 4] >>> print(len(lst)) 3
upvoted 1 times
...
peypa
8 months, 2 weeks ago
print(lst) [0, 2, 4] The answer: D
upvoted 1 times
...
blaze056
10 months, 3 weeks ago
Selected Answer: D
>>> print(lst) [0, 2, 4] >>>
upvoted 1 times
...
TheFivePips
11 months, 3 weeks ago
Selected Answer: D
If you ignore the fact the 1st is an invalid variable name and the spacing is all wonky, then the answer is D. It might be lst but its hard to know or sure because formating on this site is a nightmare for programming questions. Anyway, if we ignore that, then we evaluate each item in the list [0,1,2,3,4] according to the lamba function x % 2 == 0, where x is each subsequent item in that list. If they evaluate to true, then that item is allowed to pass the filter into the new list (that is created by the list() function). Remember that modulo % returns the remainder of the division (regardless of which way you go) 0 % 2 returns 0 1 % 2 returns 1 2 % 2 returns 0 3 % 2 returns 1 4 % 2 returns 0 only the items that evaluated to 0 will pass the filter. Thats [0,2,4] with a length of 3
upvoted 3 times
...
Mikku123
1 year, 3 months ago
It is a format issue by examtopics, read 1 as l (letter) everywhere in code.. so, D is the correct answer for this!
upvoted 1 times
...
Administrator_Of_Silly_Walks
1 year, 4 months ago
Selected Answer: B
B is the correct answer because there is no list named "list".
upvoted 2 times
Administrator_Of_Silly_Walks
1 year, 4 months ago
Also, you can't start a lists name with a number.
upvoted 1 times
...
...
Ello2023
1 year, 5 months ago
Selected Answer: B
B. you can not have a variable name where the initial character is a number '1st' it could be 'st1'. The equal sign has a gap which is not recognised in python = =, it should have been ==
upvoted 3 times
CC_DC
1 year, 4 months ago
True. The assumption is that that should be an letter "l" given the choices. If the real exam had '1st' then B would be wrong since this code would not even compile.
upvoted 1 times
...
...
jaimebb
2 years ago
Selected Answer: D
the answer is D
upvoted 1 times
...
Jnanada
2 years, 3 months ago
Correct Answer is D. If there is space, then it wouldn't give runtime error, it will give compile time error.
upvoted 1 times
...
Profstevie
2 years, 3 months ago
It is not B because either error is synthax or compiler. It is never runtime error
upvoted 1 times
...
Janpcap123
2 years, 4 months ago
The answer is #B. The code will cause a runtime exception. The actual error is: #TypeError: object of type 'filter' has no len() we cant get the len of a filter object so we can not print(len(list) The only answer is B and noting else.
upvoted 2 times
Gaddipati
2 years, 3 months ago
the answer is B but due to space between = =, len can be applied to the filter.
upvoted 1 times
...
...
palagus
2 years, 6 months ago
Selected Answer: D
It is D. len(lst) = 3
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: D
assuming code is correct: D. 3
upvoted 1 times
...
TheNetworkStudent
2 years, 8 months ago
Selected Answer: B
When you try to run this code, it errors, correct answer is B
upvoted 2 times
...
AtulVSharma
3 years, 1 month ago
1st is not valid variable name. It will give runtime error
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 ...