my_list = [i for i in range(5, 0, -1)] # Creates a list: [5, 4, 3, 2, 1]
m = [my_list[i] for i in range(len(my_list)) if my_list[i] % 2 == 0] # Include only even numbers
print(m) #[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)
#output SyntaxError: expected 'else' after 'if' expression
Ans is 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]
This section is not available anymore. Please use the main Exam Page.PCAP Exam Questions
Log in to ExamTopics
Sign in:
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.
mldprasad
4 months, 3 weeks agoseaverick
1 year, 2 months agokontra
1 year, 11 months agogekkehenk
2 years agoandr3
2 years, 1 month agoRizos
2 years, 1 month agobesha
2 years, 9 months agoangelika_az
2 years, 10 months agomacxsz
2 years, 11 months ago