wordChosen = koloi
outputList = []
for i in wordChosen:
outputList.append("_")
while missed < 6:
letter = input("Type in a letter> ")
print()
if letter in wordChosen:
index = wordChosen.index(letter)
outputList[index] = letter
print(outputList)
missed += 1
Welcome to the forums, @maditsilekota!
If I understand you correctly, this is how your code should look:
wordChosen = koloi
outputList = []
for i in wordChosen:
if not(i in outputList):
outputList.append("_")
while missed < 6:
letter = input("Type in a letter> ")
print()
if letter in wordChosen:
index = wordChosen.index(letter)
outputList[index] = letter
print(outputList)
missed += 1
If this doesn’t do what you need, just reply to this question and I’ll be happy to help!
You can add a check to see if the letter has already been guessed in the outputList . If it has, you can skip it.
wordChosen = "koloi"
outputList = ["_"] * len(wordChosen) # Initialize the list with underscores
missed = 0
while missed < 6:
letter = input("Type in a letter> ")
print()
if letter in wordChosen:
indices = [i for i, char in enumerate(wordChosen) if char == letter]
for index in indices:
if outputList[index] != letter:
outputList[index] = letter
print(outputList)
else:
missed += 1
print("end.")
Hi, @maditsilekota!
If one of the two above posts helped, please mark it as the solution so that people with similar issues can find a possible answer.