我一直在教我自己最近在Python中編程並決定製作這款遊戲。我已成功爲廣大它除了幾件事情Hangman程序中的多個錯誤
- 當一個不正確的字母輸入,字母被附加到錯誤的字母排列的遊戲空間陣列的userletter不等於在儘可能多的點。例如:如果我爲wordtarget輸入「the」,我會將t,h和e打印成錯誤的字母數組2次。不管信得到什麼伸到錯誤的字母排列
代碼:
wordTarget = raw_input("enter word here: ").lower()
gameSpace = ["_"] * Len(wordTarget)
wrongLetter = []
def main():
for x in range(0, len(wordTarget)):
while (gameSpace[x] != wordTarget[x]):
getLetter()
for i in range(0,len(wordTarget)):
if (wordTarget[i] == userLetter):
gameSpace[i] = userLetter
elif (wordTarget[i] != userLetter):
print "letter is incorrect, try again"
wrongLetter.append(userLetter)
print ("Incorrect Letters: %s" % wrongLetter)
print ("Correct Letters: %s" % gameSpace)
if (gameSpace == wordTarget):
print "Congratulations! You won"
main()
我猜問題出在了我跑環,我檢查權的方式回答但無法弄清楚。
您需要在_your question_中添加_the relevant_部分代碼。不是你的代碼的所有內容,也不是鏈接到某個非現場的地方。 – Lafexlos
'gameSpace'和'wordTarget'值是如何設置的?他們是字符串,列表還是其他東西? – Blckknght
gameSpace是一個數組,其中存儲空格和字母,如果猜對了。 wordTarget是用戶輸入並且是一個變量。 –