python - How would I code a hangman game with multiple outcomes possible? -


i trying code hangman game prints different words when player gets word amount of lives left, can't figure out how that. have else put in place expect concept. have tried elif statements, don't know else try except this:

lives_remaining = 14 guessed_letters = ''  def play():     word = pick_a_word()     while true:         guess = get_guess(word)         if first_try(guess, word):             print('excellent!')             break         elif second_try(guess, word):             print('great!')             break         elif third_try(guess, word):             print('ok!')             break         elif fourth_try(guess, word):             print('close one!')             break         elif lives_remaining == 0:             print('nope!')             print('the word was: ' + (word))             break  def first_try(guess, word):     if lives_remaining > 12:  def second_try(guess, word):     if lives_remaining > 8:  def third_try(guess, word):     if lives_remaining > 4:  def fourth_try(guess, word):     if lives_remaining > 0:  def pick_a_word():     return random.choice(words)  def get_guess(word):     print_word_with_blanks(word)     print('lives remaining: ' + str(lives_remaining))     guess = raw_input(' guess letter or whole word?')     return guess  def print_word_with_blanks(word):     display_word = ''     letter in word:         if guessed_letters.find(letter) > -1:             # letter found             display_word = display_word + letter         else:             # letter not found             display_word = display_word + '-'     print(display_word)  def process_guess(guess, word):     if len(guess) > 1:         return whole_word_guess(guess, word)     else:         return single_letter_guess(guess, word)   def whole_word_guess(guess, word):     global lives_remaining     if guess == word:         return true     else:         lives_remaining = lives_remaining - 1         return false  def single_letter_guess(guess, word):     global guessed_letters     global lives_remaining     if word.find(guess) == -1:         # letter guess incorrect         lives_remaining = lives_remaining - 1     guessed_letters = guessed_letters + guess     if all_letters_guessed(word):         return true     return false  def all_letters_guessed(word):     letter in word:         if guessed_letters.find(letter) == -1:             return false     return true  play() 

i don't know how possibly make functions work. input appreciated :)

if numberoflives == 1:     print 'response1' elif numberoflives == 2:     print 'response2' elif ... 

you use dictionary.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -