A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • one year ago

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?

  • This Question is Closed
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  2. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.