Python Python Basics (2015) Number Game App Number Game Refinement

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

Why while len(guesses) < 5? I don't get it!

Why does the function stops at 5 tries? We didn't add anything in guesses = [] so since the list is empty, why does Kenneth uses the word "hello" as an example? It just doesn't make any sense. Why 5 guesses when the list is empty?

1 Answer

Steven Parker
Steven Parker
171,314 Points

The list may start out empty, but the line that says "guesses.append(guess)" adds another item to the list each time through the loop.

So after 5 tries, the length of "guesses" will be 5 and the loop will not repeat any more.

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

You mean, every iteration of the loop is considered a new item in the list?

Steven Parker
Steven Parker
171,314 Points

That line of code adds a new item to the list each time it is executed.