[Solved] Project Hangman - part 2. What is the error trying to say?
https://code.sololearn.com/c5CJZeKW4Ic3/?ref=app Wrong answer in test #1 Before: -------i-t Letter: o After : -------i-t There is no "You already typed this letter" message, but should be Input letters: i n o i t l i t k o
7/2/2020 1:57:27 PMSubham
33 AnswersNew Answer
Russ I just want to say you win the "Developer with the Most Patience Award"! 👏 As much as I love having a community like this for learners, the medium of back and forth via posts is extremely limiting. But, if looks like you guys pushed through and it still paid off in the end.
Subham It is really difficult to help you when I don't know what the task is asking of you exactly. I can't see anything obviously wrong with your code, though.
Very kind words David Carroll - thank you. I guess a success at the end makes it all worth while!
The description you just gave says that entering the same letter twice should not reduce the attempts count. But your code goes: elif guess in guessed_letters: print('You already typed this letter') number_errors_made += 1 ...which will increase the attempts count.
It's saying that your code is not printing the line "You already typed this letter". I think I know why. Your code only adds the guess to the guessed_letters set if the letter is in the word. Try the input z z and you will see that it doesn't print the message "You already typed this letter".
Yes, but that only triggers if the original if is not satisfied, i.e. if the letter IS in the secret word.
Subham You still haven't addressed the issue that your code only checks to see if the letter that is input has already been guessed if the letter is in the secret word. As I said before, try this input z z It just says that the letter is not in the word, not that you have already guessed that letter.
I'll walk it through for you: guess: z line 22: z not in word, so if is True line 23: if is False line 25: elif is False line 27: else is triggered line 28: z added to guessed letters. line 29: printed "no such letter" line 30: extra guess added next iteration guess: z line 22: same as before, if is True line 23: same as before line 25: same as before line 27: else triggered line 28: attempted again to add z to guessed letters line 29: print "no such letter" line 30: guess added This does not print the line "already guessed" on the second guess of z.
Ok, I will try and amend it to how I would do it.
This is my code (untested on whatever platform you're using, obviously). https://code.sololearn.com/cGlG37m1Uj9t/?ref=app
That particular string shouldn't have a "." at the end I don't think. "You already typed this letter", not "You already typed this letter."
"the word", not "this word".
Sure you are. Just make sure you try and understand where what you coded before failed. That's where the learning happens.
But you have not fixed the error where (in that instance) it still prints "no such letter" and adds an extra guess after printing "already guessed"
Wrong answer in test #1 Last block contains "You are hanged!" but doesn't contain "No such letter in the word". Check the first example. These texts should be within the same block. Your last block: java---i-- Input a letter: You already typed this letter You are hanged!
If the user enters the same letter twice then the program should output You already typed this letter . Also, you should check if the user prints an English lowercase letter or not. If not, the program should print It is not an ASCII lowercase letter . Also, you should check if the user printed exactly one letter. If not, the program should print You should input a single letter . Remember that zero is also not one! Note that all these three errors should not reduce attempts count!
ok corrected but what about the output above I really don't know what it means after edit: Wrong answer in test #3 Before: ---------- Letter: k After : ---------- There is no "You already typed this letter" message, but should be Input letters: k k
I had made provision for that. what's the logical err elif guess in guessed_letters: print('You already typed this letter') line 30