我创建了一个Mastermind代码,当我试图在我的Mac上运行它时,它只是说“注销”。如果有人知道原因,那将是非常有帮助的!代码如下:
def masterMind():
number = random.ranint(10000,99999) #the computer chooses 5 random numbers
userGuess = raw_input("Guess my 5 digit password:") #asking the user to input their guess
tries = 10 # telling the computer number of tries the user is allowed
while tries < 0: # 10 attempts is the maximum amount
if number != userGuess: # if the computer's password does not equal the user's guess then it equals to one attempt
tries += 1
userGuess = input("Guess my 5 digit password:")
else: #if the user and the computer's answers align
print "Win: ", userGuess
print number
更多的“Python”(2.x)方式。修正像“00000”这样的答案,将
int
修复到str
compair。在永远不会进入循环。在
您可能需要反转比较的意义,而使用
>
。在您还需要在循环中递减
tries
,而不是递增它。在相关问题 更多 >
编程相关推荐