nerdexam
Python_Institute

PCEP-30-02 · Question #321

Consider the following code. nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x = 0 while x < 10: print(nums(x)) # Line 4 if nums[x] == 7: # Line 5 break else: x += 1 You want to print the numbers 1 to 7 to…

The correct answer is C. print(nums[x]) # Line 4 D. if nums[x] == 7: # Line 5. See the full explanation below for the reasoning.

Question

Consider the following code. nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x = 0 while x < 10: print(nums(x)) # Line 4 if nums[x] == 7: # Line 5 break else: x += 1 You want to print the numbers 1 to 7 to the monitor. But the code does not work. What do you have to change? (Choose two.)

Options

  • Ax = x + 1 # Line 8
  • Bwhile (x < 10): # Line 3
  • Cprint(nums[x]) # Line 4
  • Dif nums[x] == 7: # Line 5

How the community answered

(35 responses)
  • A
    9% (3)
  • B
    17% (6)
  • C
    74% (26)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice