For Loop incrementing by 2s instead of 1

Viewed 36

Homework: Self teaching out of a book. Still very much a novice

I create a list then print that list out using a For-Loop. It works fine.

guests=["John","Jeff","Jack","Mom"]

for i in range(len(guests)):
    print(f"I would like to invite you, {guests[i]}, to dinner.")

Now I recreate this same thing but am removing everyone from the list.

for i in range(len(guests)):
    person=guests.pop(i)
    print(f"Sorry {person}, dinner has been canceled.")

This is where it goes wrong. The code increments by 2 then says pop index out of range. If it starts at 0 and goes for the length 0,1,2,3 then why is it jumping by 2s?

0 Answers
Related