Answer:
Programming language not stated.
I'll use python for this question
Explanation:
import random
# library that we use in order to choose
# on random words from a list of words
words = ['rain, 'computer', 'science', 'program, 'python', 'mathematics', 'player', 'condition','reverse', 'water', 'board', 'geeks','learn','school','days','scholar','collar','flood','house','flies']
# Function will choose one random word from this list of words
word = random.choice(words)
print("Guess the word")
guesses = ''"
# 5 turns
turns = 5
while turns > 0:
# counts the number of times a user fails
failed = 0
# all characters from the input word taking one at a time.
for char in word:
# comparing that character with the character in guesses
if char in guesses:
print(char)
else:
print("_")
# for every failure 1 will be incremented in failure
failed += 1
if failed == 0:
# user will win the game if failure is 0 and 'You Win' will be given as output
print("You Win")
# this print the correct word
print("The word is: ", word)
break
# if user has input the wrong alphabet then it will ask user to enter another alphabet
guess = input("guess a character:")
# every input character will be stored in guesses
guesses += guess
# check input with the character in word
if guess not in word:
turns -= 1
# if the character doesn’t match the word then “Wrong” will be given as output
print("Wrong")
# this will print the number of turns left for the user
print("You have", + turns, 'more guesses')
if turns == 0:
print("You Loose")