python - finding repeat characters in a list for Hangman-python3 -
for hangman application code followed;
text=list(input("enter word guessed:")) guess=[] tries=5 clue=input("enter clue: ") print('rules:\n 1) type exit exit applcation \n 2) type ? clue') in range(len(text)): t='_ ' guess.append(t) print(guess) while true: g=input("guess letter: ") if g in text: print("you guessed correct") y=text.index(g) guess[y]=g print(guess) continue elif g=='exit': exit() elif g=='?': print(clue) elif tries==0: print ("you have run out of tries, bye bye") exit() else: print(g,' not in word') tries -=1 print("you have",tries,'tries left') continue
for code instance if text guessed 'avatar', when 'a' guessed, return first instance of letter , not positions; text[2][4]
your issue comes using y = text.index(g)
. return index of first match finds. need more akin following:
if g in text: print("you guessed correct") y in range(len(text)): if text[y] == g: guess[y] = g print(guess)
Comments
Post a Comment