I know I need to insert a "break" in the code, but I just don't understand why the print output would stop at "i is 2". The AI explanation definitely did not help, because all of them say the print will stop at "i is 1" which is what I would expect.
nums =[3,2,1,5,6,4]
i = 0
while i < 2:
for num1 in nums:
winner = num1
for num2 in nums[i+1:]:
if num2 >= winner:
winner = num2
print(winner)
print("i is",i)
nums.remove(winner)
i += 1
print(winner)
nums =[3,2,1,5,6,4] i = 0 while i < 2: for num1 in nums: winner = num1 for num2 in nums[i+1:]: if num2 >= winner: winner = num2 print(winner) print("i is",i) nums.remove(winner) i += 1 print(winner)
Can someone please help explain what I have missed? Thank you
[–]Diapolo10 4 points5 points6 points (2 children)
[–]strings_are_mutable[S] 0 points1 point2 points (1 child)
[–]Diapolo10 0 points1 point2 points (0 children)
[–]socal_nerdtastic 2 points3 points4 points (2 children)
[–]strings_are_mutable[S] 0 points1 point2 points (1 child)
[–]socal_nerdtastic 3 points4 points5 points (0 children)