So I am currently making a (far from finished) hangman game. Everything is working well except for when I try to replace the randomly picked word with underscores. The code DOES replace every character with an underscore as I wanted, but I would like for it to NOT replace the spaces within the string with the dash. For example if the randomly picked team is "New York Jets" python replaces it as so "_ _ _ _ _ _ _ _ _ _ _ _" instead of " _ _ _ (space) _ _ _ _ (space) _ _ _ _"
I don't understand what I did wrong I thought the if statement would solve the problem but it doesn't.
# doesn't replaces spaces with dash
if letter != " ":
hide = "_ " * len(secret_word)
All of the code so far
def play():
# uses underscores hide the word and to hold space for each character within the word
hide = ''
secret_word = ''
tries = 0
# Welcomes user
print("Welcome to hangman!!!")
print("Let's get started!!!")
# allows user to pick difficulty
difficulty = input("What difficulty do you want to play the game on?\nEasy = 9 tries. Normal = 6 tries. Hard = 4 tries.")
if difficulty == "easy" or "Easy":
# allows users to pick a theme
theme = input("Okay I'll pick a word, all you have to do is pick a theme :) \n Themes to pick from: History, Companies, Geography, Music, Movies, Celebrities, and Sports Team! ")
# if the theme has a subtheme
if theme == 'sports team' :
sport = input("What type of sport? Your options are: Football, Baseball, Basketball, and Hockey.")
if sport == "Football":
# imports .txt file of list
file = open('NFLTeams.txt', 'r')
NFL = file.readlines()
# randomly picks a team from the list
secret_word = random.choice(NFL)
print(secret_word)
#hides the word with underscores
for letter in secret_word:
# doesnt replaces spaces with dash
if letter != " ":
hide = "_ " * len(secret_word)
print(hide)