nerdexam
Python_Institute

PCEP-30-02 · Question #317

PCEP-30-02 Question #317: Real Exam Question with Answer & Explanation

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)
    

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice