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 trialDavid Lawson
999 PointsAny reason why he didn't count the no of guesses in the simpler way?
So I did as Kenneth suggested and tried implementing the solution before watching the video... And I managed to!! Although I did it a bit differently to him.
So when counting how many guesses, he created a list and made sure that every attempt added a 'guess' to the list. When the length of the list == 5 then it's game over.
What I did is create a n_guesses var and assigned it a value of 0. Every incorrect guess added 1 to the sum (so n_guesses += 1) and I added an overarching if so that if n_guesses < 3 then it would run the game, else it would end.
Any reason why he did it differently? Seems more complicated than it should be.
Thanks
Chris Freeman
Treehouse Moderator 68,454 PointsWhile both approaches work, tracking the previous guesses allows options on handing if previously guessed characters count as a strike or can be forgiven. It also allows unique output on repeated guesses.
There might be a speed advantage to using an integer over the list length, but it would need to be simulated to be sure.
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsJames J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsIt's been a while, but I can only suggest that both versions work of course, however, Kenneth's method stores the values of each guess, your approach does not.
If there was a need at some point to display the incorrect guesses to the user then storing them in a list and checking the length to trigger the end of the game is an approach that works