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 trialDaniel Lodestro
2,572 Pointsletter_game.py My game is tracking each correct guess as a 'strike' and the game won't end when I've guessed correctly!
I watched and re-watched, and I cannot seem to find where I slipped up. Also not sure how to include the snapshot of my code so here is the link: https://w.trhou.se/2gqn526sjl
Hopefully that works. I'm currently staring at the block that contains the strike portion, but it all looks correct to my amateur eyes.
Thanks in advance for your help!
Side note: Before each video, he asks us to pause and write the code ourselves. Is it normal for me to not have much of an idea as to how to do this? I feel like maybe the way I'm learning on Treehouse isn't helping me, but hurting me. I almost feel like a spoonfed baby, which is great sometimes, but when asked to go write code myself, I can't comprehend it or even know how to begin. I can't remember parts of the syntax etc. I suppose the question would be, is this normal? I've never written code in my life, and currently I'm using Treehouse and Codecademy simultaneously.
Jamal Scott
9,656 PointsHi Daniel, haha i gave the area where the error was for a reason, told ya it was nothing you couldn't fix :). As for the 'else', I can't seem to figure that out myself either. Programming is weird lmao
3 Answers
Jamal Scott
9,656 PointsIts normal. It took me awhile to understand your code and debug it but im still new to this as well and dont worry about the "writing code for yourself part" yet, with time you'll eventually grasp alot of the teachings and since you're new, then soaking up all that info and trying to remember will be difficult, so its better to continue with the course until its more comfortable for you. Remember you can always redo the course, if you get to the end and you're still not comfortable then I would redo the course and attempt to write the code myself then. :)
Main problem was from line 52 to 61. Nothing you couldn't fix. Happy coding https://w.trhou.se/nqqyzrcz2l
Daniel Lodestro
2,572 PointsThanks Jamal, I appreciate that. Definitely going to keep coding!
I tried changing those lines as you did, but my game is still logging correct answers as strikes, which is completely baffling me.
Chris Freeman
Treehouse Moderator 68,425 PointsYour else
is misplaced:
if guess in secret_word:
good_guesses.append(guess)
if len(good_guesses) == len(list(secret_word)):
print("You win! The word was {}".format(secret_word))
break
# unindented 4-spaces to cover "guest Not in secret_word"
else:
bad_guesses.append(guess)
Chris Freeman
Treehouse Moderator 68,425 PointsIn the while
conditional, try changing the list
to `set:
# old
while len(bad_guesses) < 7 and len(good_guesses) != len(list(secret_word)):
# new
while len(bad_guesses) < 7 and len(good_guesses) != len(set(secret_word)):
This will handle the case where secret word has multiples of a letter.
Daniel Lodestro
2,572 PointsThanks Chris!
Changed those, and after reading the comments at the bottom of the video, it says we would address it in the next video (oops!). But my original problem, which was the game is logging correct answers as strikes, and since that is the case I have unlimited guesses. I just can't seem to fix this! So frustrating!
Jason Anders
Treehouse Moderator 145,859 PointsHey Daniel,
It's been awhile since I've done Python. I've included a snapshot from my archived Workspace for you to compare code.
As for what you are feeling, I think that is completely normal. I felt exactly that way with Python and with Ruby on Rails. However, I'm very comfortable with most of the other languages, especially iOS and PHP. So, I think it will come down to what you like and what you grasp naturally. Just because you struggle with one, does NOT mean you won't excel at the others.
I gave Python (and Ruby) a break and focused on the others that I find really click with me. Don't get me wrong, I'm not bad-mouthing any language or saying stay away, I'm saying stick with what you get... focus on that... and then when you want, you can go back. I do plan to go back to Ruby and Python... just not right now.
Keep Coding! :)
Daniel Lodestro
2,572 PointsThanks for your help Jason! That's very interesting to hear. I was worried about bouncing around to the different languages. I started with Java (ultimately, my goal is to be able to create mobile apps, I'm a bit of a dreamer and would love to be able to make them a reality via mobile), and I was not understanding the syntax. The little I did learn, seemed to help me with Python. I also read that Python was a great first language to understand. Would you agree? Maybe I'll give iOS and PHP a shot.
I'm combing through your code now, thanks again!
Jason Anders
Treehouse Moderator 145,859 PointsWell, never stop dreaming. Hard work - dedication - and most importantly ... Passion will get you to where you want to go!
Daniel Lodestro
2,572 PointsDaniel Lodestro
2,572 PointsUPDATE
Collectively, you were all very helpful.
Chris: You were addressing a problem that was to be handled in the following video, still a problem though, just not the help I was looking for at this particular time.
Jamal: Your code was the most helpful. The ending lines though, weren't working for me. Not sure what it was, but the game would work for about 5 guesses, and then crash and restart. I went line by line and debugged my own while looking at yours, and found the problem. It was line 58, your indentation was correct and mine was not. Unbelievable that such a small mistake could be so disastrous! Well, I guess it is believable haha. So now, I'm looking at it trying to figure out why line 58, else: bad_guesses.append(guess) would have effected the game to where my correct guesses were counted as strikes, and incorrect guesses were not.
Thanks for your help Jamal!
Jason, I'll be using your code when I start the next portion of the game, since I'm guessing your code is the complete/finished product, and mine is just in its first stage.
Thanks again everyone!