Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- word = input('Insert a word to be guessed\n')
- show_word = '_' * len(word)
- print('\n' * 100)
- guesses_allowed = 10
- guessed_lettres = set()
- wrong_guessed_letters = set()
- while True:
- user_guess = input(f'Guess a letter or word: {show_word}\n')
- if len(user_guess) == 1:
- guessed_lettres.add(user_guess)
- show_word = ''.join([c if c in guessed_lettres else '_' for c in word])
- if '_' not in show_word:
- print(f'you completed the word: {word}\n ,You win!!')
- elif user_guess not in word:
- wrong_guessed_letters.add(user_guess)
- pass
- elif len(user_guess) > 1:
- if user_guess == word:
- print(f'you guessed the word: {word}\n ,You win!!')
- break
- else:
- for l in user_guess:
- if l in word:
- guessed_lettres.add(l)
- show_word = ''.join([c if c in guessed_lettres else '_' for c in word])
- elif l not in word:
- wrong_guessed_letters.add(l)
- print(f'Sorry "{user_guess}" is not the correct word')
- print(f'wrong letters already guessed: {wrong_guessed_letters}')
- guesses_allowed -= 1
- if not guesses_allowed:
- print(f'You finish your allowed guesses, the word was: {word} , Game over')
- break
Advertisement
Add Comment
Please, Sign In to add comment