Question
**Need a solution in python 2.7. I have also attached the code I wrote for the computer to generate a random word which it reads
**Need a solution in python 2.7. I have also attached the code I wrote for the computer to generate a random word which it reads from a txt file and generates a set of blanks representing the number of letters in the random word. That was question 1, we have to use that randomly generated word in our word game.
In this exercise we want to implement a word game. The computer should randomly choose a word and the player is supposed to guess the word. Your program just give the number of letters as the clue to the user, then user starts guessing the letters. If the letter is used in the word, program show the location(s) of the letter. Before asking for another letter guess, program should ask the user if she/he wants to guess the word (maybe the user already guessed the word). The program should continue until the user gets the correct word or guesses all letters. At then show how many attempts the user made.
The following is an interaction example (assume the word is mission):
Welcome to the word game! _ _ _ _ _ _ _
Would like to guess the word (no/yes)? no
Guess a letter? a
_ _ _ _ _ _ _
Would like to guess the word (no/yes)? no
Guess a letter? m
m _ _ _ _ _ _
Would like to guess the word (no/yes)? no
Guess a letter? e
m _ _ _ _ _ _
Would like to guess the word (no/yes)? no
Guess a letter? i
mi _ _ i _ _
Would like to guess the word (no/yes)? no
Guess a letter? s
missi _ _
Would like to guess the word (no/yes)? yes
Guess a word?
Missing
Wrong guess
Would like to guess the word (no/yes)? no
Guess a letter? n
missi _ n
Would like to guess the word (no/yes)? yes
Guess a word?
mission
Congratulations! 8 attempts!
import random def read_File(filename): fhand = open(filename) List = [] for i in fhand: i = i.strip() List.append(i) return List
randomWord = (random.choice(read_File("words.txt"))) randWord = randomWord.lower()
blanks = '_ ' * len(randomWord) print 'Welcome to Guess the word game!:', blanks
****Sample words from from txt file "words.txt"
ABA ABAC ABACA ABACAS ABACI ABACK ABACS ABACTERIAL ABACTINAL ABACTINALLY ABACTOR ABACTORS ABACUS ABACUSES ABAFT ABAKA ABAKAS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started