我在使用这个刽子手编码时遇到了麻烦。当我运行代码时,它会询问“输入一个字母a - z”这个问题,但是当我输入一封信而不是写一封信时,它只是从头开始问同样的问题而不让我知道是否信是否正确。
import random
possibleAnswers = ["page","computer","cookie","phishing","motherboard","freeware","bus","unix","document","hypertext","node","digital","worm","macro","binary","podcast","paste","virus","toolbar","browser"]
random.shuffle(possibleAnswers)
answers = list(possibleAnswers[1])
display = []
display.extend(answers)
for i in range(len(display)):
display[i] = "_"
print ' '.join(display)
print "\n\n\n\n"
count = 0
while count < len(answers):
guess = raw_input("Type in a letter a - z: ")
guess = guess.upper()
for i in range(len(answers)):
if answers[i] == guess:
display[i] = guess
count += 1
print ' '.join(display)
print "\n\n\n"
答案 0 :(得分:2)
它 告诉你,经过时尚。问题是你的整个单词列表是小写的,但你明确地将所有输入猜测改为大写。那些不能匹配,所以永远不会有“正确”的猜测。将单词列表更改为大写字母,或将您的转化时间从upper
更改为lower
。