I am trying to make a hangman game for class and I am stuck on how to replace a dash (-) with a correctly guessed letter.
Like if the word was HAPPY and the user guessed the letter p, so it would replace the dash for a letter and look like this: --PP-
Here is my code so far:
def play_game(secret_word):
guesses_left = 8
hangman_dash = len(secret_word) * "-"
while guesses_left > 0:
print("The word now looks like this: " + (hangman_dash))
print("You have " + str(guesses_left) + " guesses left")
letter = input("Type a single letter, then press enter: ")
letter = letter.upper()
if len(letter) != 1:
print("Please enter only one letter.")
elif letter not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ':
print("Please guess a letter.")
if letter in secret_word:
print("That guess is correct")
else:
print("There are no {}'s in the word".format(letter))
guesses_left = guesses_left - 1