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 trialMichael Nock
Android Development Techdegree Graduate 16,018 PointsReason for putting "guesses.append(guess)" at the end.
In the video Kenneth mentions that we have to put it at the end of the While loop, after we check if a player has guessed correctly or not. However, the while loop condition is only checked once it's reached the end of the loop, so it really shouldn't matter where you put the append. Even if you put it first it'll run through the rest of the code. Having to interrupt the code to evaluate "len(guesses) < 5" after every single instruction would be much more processor intensive ;)
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsYou are correct in that there is some leeway in where the append
can be placed. Anywhere within the else
block of the try
statement works. This makes sure the guess was valid before appending it.
Not sure about your "evaluate... after every single instruction" comment. The while
condition is only evaluated once before the start of each loop.
Michael Nock
Android Development Techdegree Graduate 16,018 PointsMichael Nock
Android Development Techdegree Graduate 16,018 PointsThat's what i was saying, that there's no listener or anything attached looking for changes to the guesses list, it only evaluates the condition once per loop (at the start). :)
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsGreat. Sorry I misread your post