У меня возникли проблемы с получением правильного вывода из моего кода. Мне нужно, чтобы он обеспечивал голову, тело, руки, ноги один за другим, но это не так. Проверьте мой код.У меня возникли проблемы с программой Hangman, которую я сделал
import random
max_wrong = len(HANGMAN) -1
WORDS = ("Caleb","Owen","Ben","Adriane","Marley")
word = random.choice(WORDS)
so_far = "-" * len(word)
wrong = 0
used = []
while wrong < max_wrong and so_far != word: #The start of the sequence to make it loop
print(HANGMAN[wrong])
print("you used the following letters: ",used)
print("So far the length of the word is ",so_far)
guess = raw_input("What letter do you think is in the word? ")
guess = guess.upper()
while guess in used:
print("Hey,wait a minute you have already guessed that word.")
guess = raw_input("What letter do you think is in the word? ")
guess = guess.upper()
used.append(guess)
if guess in used:
print('Yes',guess,"is in the word")
# new so_far
new = " "
for i in range(len(word)):
if guess == word[i]:
new += guess
else:
new += so_far[i]
max_wrong = len(HANGMAN) -1
so_far = new
else:
print("Sorry ", guess, " is not in the word")
wrong += 1
if wrong == max_wrong:
print(HANGMAN[wrong])
print"Oops sorry you have been hanged!"
else:
print("You guessed it the word was ",word)
Кстати, я уже создал кортеж с «графикой», но переполнение стека не позволил бы мне показать, что я оставил позади. Он не будет обеспечивать тело, и он продолжает говорить, что письмо находится в слове. Выход это несмотря на то, что не в слове
------
| |
|
|
|
|
|
|
|
----------
('you used the following letters: ', [])
('So far the length of the word is ', '-----')
What letter do you think is in the word? n
('Yes', 'N', 'is in the word')
------
| |
|
|
|
|
|
|
|
----------
('you used the following letters: ', ['N'])
('So far the length of the word is ', ' -----')
What letter do you think is in the word? k
('Yes', 'K', 'is in the word')
------
| |
|
|
|
|
|
|
|
----------
('you used the following letters: ', ['N', 'K'])
('So far the length of the word is ', ' ----')
What letter do you think is in the word?
Как насчет того, чтобы дать какое-то описание того, что это такое и чего не происходит. –
Вы должны добавить вопрос. И пример того, что результат и что вы ожидаете. – Kapep
Является ли отступ в вашем коде точно таким, как показано выше? –