problem set 3 hangman.. I wish it's almost done, but when I got correct word it should print new one which is replace the word with '_' but it's adding up.
can anybody help me?
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
ansWord = choose_word(wordlist)
#ansWord = list(ansWord)
letters = 'abcdefghijklmnopqrstuvwxyz'
guessNumber = 8
guess = ''
while (guessNumber > 0):
guessLetter = raw_input('Please guess a letter: ')
letters = letters.replace(guessLetter, "")
def goodGuess(guessLetter, guess):
guess = guess
for c in ansWord:
if c in guessLetter:
guess = guess + c
guess = guess + '-'
def badGuess(guessLetter, guess):
if guessLetter in ansWord:
print 'Good guess: '+ goodGuess(guessLetter, guess)
guess += goodGuess(guessLetter, guess)
guessNumber -= 1
print 'Opps! That letter is not in my word: ', badGuess(guessLetter, guess)
guess = badGuess(guessLetter, guess)
print 'You have' ,guessNumber, 'guesses left.'
print 'Available letters: ', letters
if goodGuess(guessLetter, guess) == ansWord:
print 'congratulations, you won!'
elif guessNumber == 0 :
print 'You lost! The answer is' , ansWo
Line 5 in the function has a single double quote, which starts a literal string, so everything until the next double quote is treated as a string instead of code.
Define your functions outside of your hangman function and then call them where needed. It will help make your code more readable. One thing to remember in this assignment is that strings are arrays of characters and you can address each letter individually.