Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14097

Replacing "_" in Hangman Game with a Player Guess for All Matches

$
0
0

I'm getting started with coding and I tried to programm "Hangman". Now I figured most of the stuff on my own, but I'm struggling with this one.I want to save multiple indexes, so that i can replace "_" to the needed character.

guess = ""for x in randomWord:    guess = str(guess) +"_"#Calculates the index for the found lettefor i in randomWord:    wordIndex = randomWord.find(userInput)#If Statement deconstructs string into list and adds found letter if wordIndex > -1:    guess = list(guess)    guess[wordIndex] = userInput    guess = "".join(guess)    missLett -= 1

I read somewhere, that enumerate could help me with my problem, but just couldn't get the hang of it.


Viewing all articles
Browse latest Browse all 14097

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>