Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.