I want to print a message on the screen saying "you have already entered that letter" ONLY in the case the letter was entered previously. If the letter is being entered for the first time it should not print that. Below is my code but it prints the message even when the letter is entered for the first time:
import requests
import random
import hangman_art #import logo
word_site = "https://www.mit.edu/~ecprice/wordlist.10000"
response = requests.get(word_site)
WORDS = response.text.splitlines()
chosen=random.choice(WORDS) #use this or lines 8,9,10
#https://stackoverflow.com/questions/75139406/how-to-pick-a-string-from-a-list-and-convert-it-to-a-list-python?noredirect=1#comment132596447_75139406
# ~ rand=random.randint(0,10000)
# ~ pick=WORDS[rand]
# ~ pick_as_list=list(pick)
print(hangman_art.logo)
print(chosen)
stages = ['''
+---+
| |
O |
/|\ |
/ \ |
|
=========
''', '''
+---+
| |
O |
/|\ |
/ |
|
=========
''', '''
+---+
| |
O |
/|\ |
|
|
=========
''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========
''', '''
+---+
| |
O |
|
|
|
=========
''', '''
+---+
| |
|
|
|
|
=========
''']
x=[]
lives=6
for letter in chosen:
x+='_'
s=' '.join(x)
print(s)
while '_' in x:
user=input("Guess a letter: ").lower()
if user in chosen: #<---------------------------- My trial
print(f"You've already guessed {user}")
for i in range(0,len(chosen)):
if chosen[i]==user:
x[i]=user
s=' '.join(x)
print(s)
if '_' not in x:
print("You Win!")
if user not in chosen:
lives-=1
print(stages[lives])
print(f"You guessed {user}, that's not in the word. You lose a life ({lives} left).")
if lives==0:
print("You lose.")
break
Also I noticed it takes a life from the user if they repeat the wrong letter. I want it to take a life only for the first trial of a wrong letter.