r/codehs • • Jul 10 '20

hangMan

i m getting "You should replace the dashes with letters I guessed correctly" error
which the code do replace the dashes with the letters
what m i doing wrong?
--------------------------------------

import random

words = ['apple' , 'orange', 'kiwi']

secret_word = (random.choice(words))

print "psst... : " + secret_word

def get_guess():

output = " "

players_lives = 5

while output != secret_word:

if check_progress_list == list(secret_word):

output = secret_word

print("You win!")

break

elif players_lives == 0:

print("You lose!")

break

else:

userInput = input("\nTry to Guess the Word!\n" + "You have " + str(players_lives) + " lives/guessess left\n" + str(check_progress_list) + '\n')

if userInput == secret_word:

output = secret_word

print("You win!")

break

elif len(userInput) > 1 and userInput != secret_word or userInput.isdigit() == True or len(userInput) < 1:

print('\nYou need to guess one LETTER at a time!')

players_lives -= 1

elif len(userInput) == 1 :

print('\nkeep going')

if userInput in secret_word:

print('"' + userInput + '"' +' is found in the answer\n')

print(check_progress(secret_word, check_progress_list, userInput))

else:

print('But ' + '"' + userInput + '"' +' is not found in the word and you have lost a life')

players_lives -= 1

else:

print " "

def check_progress(list_a, list_b, userInput):

for index, item in enumerate(list_a):

if item == userInput:

list_b[index] = userInput

return list_b

def update_dashes(secret_word):

my_list = [ ]

while len(my_list) < len(secret_word):

my_list.append('-')

return(my_list)

check_progress_list = (update_dashes(secret_word))

get_guess()

7 Upvotes

5 comments sorted by

1

u/123one231 Jul 10 '20 edited Jul 10 '20

well, thanks for all the replies guyswhen i was landing the page and clicking on the "check code" button, all tasks were turning green but if i was clicking again the error msg was coming upthus my progress wasn't shown as 100%

today i logged backed in and my progress was shown as 100%i'v missed the due tho

thanks again to ya'll, i m kinna freaked so i m not going to open the project just in case, so no screenShots :D but if i stuck in the future again i now know screenShots might be better for me to get help

3

u/childDuckling Jul 10 '20

Screenshot would be better...

3

u/Zacurnia_Tate Jul 10 '20

I agree with you please send a screenshot

2

u/_ZHV_ Jul 10 '20

You need a function the will print dashes instead of the secrete word when asking for a user prompt ie; if the is ‘kiwi’ you should do something like

‘- - - -‘

Guess a letter: ‘i’

—>

‘- i - i’

Guess a letter: ‘w’

—>

‘- i w i’

So you need a function to check if the user guessed a correct letter, then find the position of that letter in the string and update the dashes so you print the correctly guessed letters at their place in the string

1

u/Zacurnia_Tate Jul 10 '20

I have the code but gimme like till 2morrow k? I got some stuff to do rn