我無法從我的代碼中獲取正確的輸出。我需要它一個一個地提供頭部,身體,手臂和腿部,但它不會。請檢查我的代碼。我遇到了我製作的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
您的代碼中的縮進是否完全如上所示? –