Hangman Report
Hangman Report
Hangman Report
Python Code
import random
def hangman():
restart = ('Y')
while restart not in ('n', 'NO', 'no', 'N'):
name = input("What is your name? ")
words = ['rainbow',
'python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board']
word = random.choice(words)
guesses = ''
turns = 12
if char in guesses:
print(char)
else:
print("_",end=" ")
failed += 1
if failed == 0:
print("You Win")
restart = input("You want to play Again")
guesses += guess
turns -= 1
print("Wrong")
if turns == 0:
print("You Lose")
restart = input("You want to play")
hangman()
Output
Summary
The program for this task is about hangman game which stores some words and let the user
play the game by guessing the characters within a word. The game starts with the message to
ask user name. User will enter the name and the game print the user name with a “Good Luck”
message and ask the user to guess the character in a word by inputting a character. If the
guessed character is found in a word, then program asks the user to enter/guess another
character. If the character is wrong the program display “Wrong” and also display the
remaining guesses. In this game user have 12 guesses to attempt and every time when the
guess is wrong it will subtract one value from total turns.
By using this structure, program uses for and while loop to repeat and
increment/decrement the values of certain variables which are already defined in pseudo and
python code.
If the user guess all the characters in a word correct then program displays a message
“You Win” and when all the guesses are wrong then program displays a message “You Lose”. If
the user wants to play again the program restart the game by let the user to input ‘Y’ with a
input message “You want to play”, then end of hangman() function and end of main() function.