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

Kindly could you explain this part**while len(bad_guesses) < 7 and len(good_guesses) != len(secret_letter):**please.

Dear Kenneth, hope you are fine,

please i need some help that i didnt get the idea yet why we use len(good_guesses) != len(secret_letter in the vedio you said that letter in both list are same so why we use
*** != *** between them ??

Many thanks.

2 Answers

Steven Parker
Steven Parker
229,921 Points

There's two things being tested there at the same time. The first is "len(bad_guesses) < 7" which is checking that the number of misses is less than 7 (otherwise the player loses). The other test is "len(good_guesses) != len(secret_letter)" and "!=" is the inequality comparison (it means "is not equal to"). So this test is checking that the number of good guesses is not the same as the number of letters in "secret_letter" (otherwise the player has won). Either way, it would mean the game is over which is what the entire expression is testing.

Note that comparing good guesses with the word size only works if every letter in the word is different. You would need different logic to correctly determine a win of the word had multiples of any letter (like "color").

I can't seem to wrap my head around this concept. Wouldn't you want to make good_guesses = secret_word to show that they player won?

Steven Parker
Steven Parker
229,921 Points

Well, one is a list and the other is a string, so at most you would only compare their lengths. But as I said, that won't always show a win. For example, the word "beep" has 4 letters, but only takes 3 guesses to win.