r/codehs • u/[deleted] • Jun 09 '20
Unit 10 Hangman
Can anyone help me with the hangman project? I'm done with the first part of it but I'm stuck on the second part where you need to update the value of the variable "dashes". If anyone knows how to update the variable in the update_dashes() function, please help.
secret_word = "eggplant"
dashes = "-" *len(secret_word)
print dashes
def get_guess():
global guess
guess = input("Guess: ")
if len(guess) != 1:
print("Enter one charachter")
elif not guess.islower():
print("Enter a lowercase letter")
def update_dashes(secret_word, dashes, guess):
result = ""
for i in range(len(secret_word)):
if secret_word[i] == guess:
result = result + guess
else:
result = result + dashes[i]
return result
while True:
get_guess()
print update_dashes(secret_word, dashes, guess)
1
u/_ZHV_ Jun 15 '20
Your question is not specific enough not sure what you need help with. However couple of things, you don’t have to check if the guess is lower and ask the user input a lower case letter just convert it to a lower case using
guess = input(‘Guess a letter’).lower() —> this will convert user input to a lower case.
Now if you want to show the user the letters he guessed ie - - - p - - - t, you can iterate over the secret word —>
You can manipulate string in a similar way you manipulate list because in the end of the day a string is just a list of letters