Python hangman game. Python 3 -


i trying create simple hangman game using python. have faced problem can't solve , grateful receive tips guys.

okay provide sample of code , below explain issue is:

# here list of words words = ['eight', 'nine', 'seven'...] # choosing random word list word = random.choice(words)  # creating empty list store result  secret_word = []  # creating count variable use later determinate if player wins count = 1  letter in word:     secret_word.append('_') secret_word[0] = word[0]  user_guess = input("enter letter: ")  # here if user guesses letter # place letter on spot in our secret_word while user_guess:     if user_guess in word:         print("correct letter.")         # adding 1 count every guessed letter         count += 1         # replacing '_' letter         letter in range(len(word)):             if user_guess == word[letter]:                 secret_word[letter] = word[letter]         # here checking if user has won         if count == len(word):             print("you win!") 

i gave part of program because don't think there's need entire code.

my problem in count variable. can see adding + 1 variable every time when user guesses correct letter when count variable = len(word) little program know user had won.

anyways when 1 single letters appears twice in word example word 7 haves letter e 2 times count variable still goes 1 user cant win in case this. have absolutely no idea how fix , happy receive hints.

thank , please excuse bad english , coding skills

you increment count whenever replace underscore correct letter. way, count equal number of letters correct in word far.

to more clear, move count += 1 in if statement when replace underscores actual letter.

one problem see you're giving player first letter , initializing count 1. don't know why you're doing this, if first letter occurs more once, won't reflected in word, , player still have guess letter anyways.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -