nerdexam
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)
  • A
    17% (5)
  • B
    73% (22)
  • C
    7% (2)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice