Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,271 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
231,271 Points

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