AharonSarShalom

HangMan

Jan 5th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. word = input('Insert a word to be guessed\n')
  2. show_word = '_' * len(word)
  3. print('\n' * 100)
  4.  
  5. guesses_allowed = 10
  6. guessed_lettres = set()
  7. wrong_guessed_letters = set()
  8. while True:
  9.     user_guess = input(f'Guess a letter or word: {show_word}\n')
  10.     if len(user_guess) == 1:
  11.         guessed_lettres.add(user_guess)
  12.         show_word = ''.join([c if c in guessed_lettres else '_' for c in word])
  13.         if '_' not in show_word:
  14.             print(f'you completed the word: {word}\n ,You win!!')
  15.         elif user_guess not in word:
  16.             wrong_guessed_letters.add(user_guess)
  17.             pass
  18.     elif len(user_guess) > 1:
  19.         if user_guess == word:
  20.             print(f'you guessed the word: {word}\n ,You win!!')
  21.             break
  22.         else:
  23.             for l in user_guess:
  24.                 if l in word:
  25.                     guessed_lettres.add(l)
  26.                     show_word = ''.join([c if c in guessed_lettres else '_' for c in word])
  27.                 elif l not in word:
  28.                     wrong_guessed_letters.add(l)
  29.             print(f'Sorry "{user_guess}" is not the correct word')
  30.     print(f'wrong letters already guessed: {wrong_guessed_letters}')
  31.     guesses_allowed -= 1
  32.     if not guesses_allowed:
  33.         print(f'You finish your allowed guesses, the word was: {word} , Game over')
  34.         break
Advertisement
Add Comment
Please, Sign In to add comment