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

David Lawson
David Lawson
999 Points

Any 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.


James J. McCombie
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 20,022 Points

It'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

Chris Freeman
Chris Freeman
Treehouse Moderator 59,731 Points

While 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.