我寫的樂趣(掛起的人)一個計劃,我得到這個while循環完美正確的while循環無效的語法?
while wrong MAX_WRONG and so_far != word:
我的整個程序incorrrect語法是這個
import random
HANGMAN=(#this is the Hangman ascii art
"""
_________
| |
| 0
|
|
|
|
_________
| |
| 0
| |
|
|
|
_________
| |
| 0
| /|\\
|
|
|
_________
| |
| 0
| /|\\
| /\\
|
|
""")
MAX_WRONG=len(HANGMAN)-1
WORDS=("OVERUSED","CLAM","BACON","PUCK","TAFFY") #these are the words
word=random.choice(WORDS) #this is teh word that is going to be guessed
so_far="-"*len(word)#where the orrect letteres are viewd
wrong=0
used=[]# the letters incorrectly guessed
while wrong MAX_WRONG and so_far != word:
print HANGMAN[wrong]
print "YOu have used:\n",used
print "\nso far the word is:\n",so_far
guess=raw_input("\n\nEnter your guess:")
guess=guess.upper()
while guess in used:
print "You have already guessed the letter".guess
guess=raw_input("enter your guess")
guess=guess.upper()
used.append(guess)
if guess in word:
new=""
for i in range(len(word)):
if guess==word[i]:
new+=guess
else:
new+=so_far[i]
so_far=new
else:
print "INCORRECT"
wrong+=1
if wrong==MAX_WRONG:
print HANGMAN[wrong]
else:
print "YAAAAY"
print "the word was",word
所有幫助表示讚賞!
「在完全正確的while循環無效的語法?」對我來說似乎並不正確。 – MByD
所以,除了反對票之外,我們可以得到一些選票嗎? : -/ – 2011-12-11 00:19:42
當編譯器說它不是一個好的策略時,聲稱代碼是正確的 - 大多數人都會相信編譯器。如果你說「幫我找到我的錯誤」,那麼下次你會得到更少的讚譽(我沒有堆積 - 7就夠了)。 – Dave