Question: It's a Python question, I got confused which I cannot get the same result as the example below. An example interaction can look like this:

It's a Python question, I got confused which I cannot get the same result as the example below.

An example interaction can look like this:

>>> Welcome to Hangman! _ _ _ _ _ _ _ _ _ >>> Guess your letter: S Incorrect! >>> Guess your letter: E E _ _ _ _ _ _ _ E

_____________mycode___________________

word = 'AABBCC' word = list(word) wordlist = ['_' for i in range(len(word))]

if __name__ == '__main__': print('Welcome to Hangman!') guess = input('Guess your letter: ') guess.upper() # count that how many times to reach the final ans; # but first to init; count = 0 repeat = True while repeat: # if guess letter in the wordlist if guess.upper() in wordlist: count += 1 print('Invalid input, the letter already exits.') guess = input('Guess your letter: ') if guess.upper() in word: count += 1 for index in range(len(word)): if guess.upper() == word[index]: index = word.index(guess.upper()) wordlist[index] = guess.upper() print(' '.join(wordlist)) guess = input('Guess your letter: ') # if guess.upper() not in word else: count += 1 print('Incorrect!') guess = input('Guess your letter: ') # if wordlist all have letters, and no '_', then win; if '_' not in wordlist: print('You finally found the word.') print('You totally use %d times' %count) repeat = False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!