Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

List and discuss the three preconditions for economic growth.

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

8-6 Who poses the biggest security threat: insiders or outsiders?

Answered: 1 week ago