PCEP Control Flow, Loops, Lists and Logic • Set 5
PCEP Control Flow, Loops, Lists and Logic Practice Test 5 — 15 questions with explanations. Free, no signup.
A program uses a while loop to find the largest number in a list until a negative number is encountered. What is wrong with this code?
numbers = [3, 7, 2, -1, 5] max_num = 0 i = 0
while numbers[i] >= 0:
if numbers[i] > max_num:max_num = numbers[i] i += 1
print(max_num)Choose an answer to begin — your selection is scored in the full session.
15 questions · instant feedback and full explanations after every question.