Python_Institute
PCEP-30-02 · Question #317
Consider the following code. ``python data = ['Peter', 'Paul', 'Mary', 'Jane'] res = 0 `` Which of the following code snippets will expand the code, so that 100 will be printed to the monitor?…
The correct answer is B. ```python for i in ('Peter', 'Steve', 'Jane'): if i in data: res += 50 print(res) ```. See the full explanation below for the reasoning.
Question
Consider the following code.
data = ['Peter', 'Paul', 'Mary', 'Jane']
res = 0
Which of the following code snippets will expand the code, so that 100 will be printed to the monitor? (Choose two.)Options
- A
for i in ('Peter', 'Steve', 'Jane'): if i in data: res += 100 print(res) - B
for i in ('Peter', 'Steve', 'Jane'): if i in data: res += 50 print(res) - C
for i in ('Peter', 'Steve', 'Jane'): if i not in data: res += 100 print(res) - D
for i in ('Peter', 'Steve', 'Jane'): if i not in data: res += 100 print(res)
How the community answered
(30 responses)- A17% (5)
- B73% (22)
- C7% (2)
- D3% (1)
Community Discussion
No community discussion yet for this question.