I am more accustomed to C# than Python. As just something to do in my spare time I decided to make a simple hangman console application in Python. Player 1 inputs a word, player 2 then has 5 attempts to guess it. Say the word is "hello" once they make a guess, lets say "d" it would print _ _ _ _ _ . If their guess was "e" it would print _ e _ _ _ .
For some reason no matter whether I guess a correct or incorrect letter it just displays one _
word = input("Player 1, please enter a word: ")
lives = 5
print("Player 2, you have {} lives left.".format(lives))
print("The Word: ", "_ " * len(word))
wordSuccessfullyGuessed = False
while lives > 0 or wordGuessed:
guess = input("Player 2, guess a letter: ")
wordFormatted = ""
for char in word:
if char in guess:
wordFormatted = char + " "
else:
wordFormatted = "_ "
print(wordFormatted)