Hangman Code
Hangman Code
Name:Subiksha A R A
Sec:11
Roll no:60
Department:ECE
Develop a hangman game in Python that randomly generates a word and prompts
the user to guess one letter at a time, as shown in the sample run. Each letter in
the word is displayed as an asterisk. When the user makes a correct guess, the
actual letter is then displayed. When the user finishes a word, display the number
of misses and ask the user whether to continue playing. Create a list to store the
words, as follows:
def pick_a_word():
def play():
e) Also, use suitable flag variable to monitor the number of times a user fails
by guessing wrong character
Sample Run:
(Guess) Enter a letter in word p*** > r (Guess) Enter a letter in word prr* > p p is
already in the word
(Guess) Enter a letter in word pro*r** > g (Guess) Enter a letter in word progr** >
n n is not in the word
Python Code:
import random
def pick_a_word():
return random.choice(words)
def hide_word(word):
def play():
word = pick_a_word()
hidden_word = hide_word(word)
turns = 15
missed = 0
guessed_letters = []
guess = input().lower()
continue
if guess in guessed_letters:
continue
guessed_letters.append(guess)
if guess in word:
for i in range(len(word)):
if word[i] == guess:
else:
missed += 1
turns -= 1
if turns == 0:
else:
if response.lower() == 'y':
play()
play()
Output:
>