Design a word guess game. Ask player 1 to input a word. Then player 2 guesses th
ID: 3791320 • Letter: D
Question
Design a word guess game. Ask player 1 to input a word. Then player 2 guesses the word. If the guessed word is not correct, program says "Your guess is not correct!". Player 2 can guess unlimited times until the answer is correct, or type "@exit" to quit the program. When player 2 types "@hint", print out the first and last letter of the word. When players 2 types "@hint" again, randomly tells one of the other unknown letter. After this, every time player 2 input "@hint", randomly tells one of the other unknown letter until no more unknown letters. If the guess is correct, print out "Yes! ! ! ! !"Explanation / Answer
from random import randint
word=raw_input("Player 1:Enter word ")
guess=""
flag=0
while guess!=word:
guess=raw_input("Player 2:Enter guess word ")
if guess=="exit":
break
elif guess=="hint" and flag==1:
print word[randint(0,len(word))]
elif guess=="hint" and flag==0:
print word[0],word[len(word)-1]
flag=1
elif guess==word:
print "Yes "
else:
print "Your guess is not correct "
======================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ python wordguess.py
Player 1:Enter word
hello
Player 2:Enter guess word
hint
h o
Player 2:Enter guess word
hello
Yes
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.