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) Letter Game App Letter Game Introduction

Why we need add code:" and len(good_guesses) != len(list(secret_word)): "

I've tried remove that code, this game work very well. I really don't understand why we need that.

     while len(bad_guesses) < 7 and len(good_guesses) != len(list(secret_word)): 

what problem will cause if we only have below code:

    while len(bad_guesses) < 7:

1 Answer

this part ........... and len(good_guesses) != len(list(secret_word)):

helps you check if you are done with the game (completed successfully); or if still have more trials to go.

if I have a word 'abcd'

and you guessed all 4 letters correctly

then

4 != 4 is false ... do something ... probably exit the game

but if you only guessed 3 so far, and bad_guesses is still < 7 then

3 != 4 is true ... do something ... probably continue the game.