anonymous
  • anonymous
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 :)
SOLVED
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.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
def hangman(): 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 else: guess = guess + '-' return guess def badGuess(guessLetter, guess): return guess if guessLetter in ansWord: print 'Good guess: '+ goodGuess(guessLetter, guess) guess += goodGuess(guessLetter, guess) else: guessNumber -= 1 print 'Opps! That letter is not in my word: ', badGuess(guessLetter, guess) guess = badGuess(guessLetter, guess) print '-----------' 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
rsmith6559
  • rsmith6559
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.

Looking for something else?

Not the answer you are looking for? Search for more explanations.