I am writing a code for hangman game. In which I pick one random word from a text file and then user have to guess that word letter by letter. I face one problem while I iterating loop from the correct word. I try to iterate this loop for a comapring current word with the gussed word
I tried many solutions from other websites but it won't be working. I also tried run this code in idle line by line but with some different and logically both are same and In idle it won't give me any error or any warning
def guess_word(letr,empty,correct_word):
if(letr.upper() in empty):
return("Already guessed!!" + empty)
elif(letr.upper() in correct_word):
print("You gussing correctly")
n=0
for n in correct_word:
print(type(empty))
if correct_word[n]==letr:
print(type(empty))
empty.replace(empty[n],letr.upper())
n+=1
return(empty)
in main function:
while correct_word!=e:
letr=input("Guess your letter: ")
z=guess_word(letr,empty,correct_word)
print((z))
This the function in which I face an error. I enter code here`ant to compare correct_word(actual word) letter by letter(letr) with empty(user's guessed word) and replace a letter with the empty string letter. And I also include some part of my main function which shows how I call my function