I'm new to python and have been working through a book. At the end of the chapter there was a challenge to create a game where the computer picks a random word and the player has to guess that word. The computer tells the player how many letters are in the word. The player gets five chances to ask if the letter is in the word. The computer responds with only a yes/no. The player then has to guess the word. Here is my attempt at this:
print ("\t\t\tWelcome to the guess my word challenge")
print ("\nThe computer will pick and random word and you have to guess it in five tries")
import random
#create sequence of words
WORDS = ("computer","laptop","mouse","keyboard")
#pick random word
word=random.choice(WORDS)
correct=word
tries=0
print ("This word has ",len(word), "letters")
i=""
while word != "" and tries<5:
for i in word:
i=input("Guess a letter: ")
if i not in word:
print ("No")
else:
print ("\nYes")
tries+=1
if tries==5:
print("You've run out of tries")
final=input("\nGuess my word: ")
if word==correct:
print ("Well done that was my word!")
else:
print ("Better luck next time")
input ("\n\nPress the enter key to exit")
Now the problem I'm having is I can't get the tries bit to work, eventually the program will say you've run out of tries but I want it to say that after 5 tries. Also, no matter what word I put in at "guess my word", it always displays its correct even if it isn't.
finalafter you ask for it - did you intend to comparefinal==correct?