我想在Python中編寫一個簡單的「密碼」程序,允許3次嘗試在遞歸函數中「登錄」。我不明白爲什麼它不工作,但...(是的,侏羅紀公園的啓發)如何使用Python中的遞歸計數器?
def magicWord(count):
int(count)
answer = raw_input("What is the password? ")
if answer == 'lucas':
print 'ACESS GRANTED'
else:
count =+ 1
if count > 2:
while count > 2:
count+=1
print "na na na you didn\'t say the magic word. "
else:
magicWord(count)
magicWord(0)
你的意思是'數+ = 1'後別的':'? – 2012-04-21 06:04:31
帶有int(count)的行不做任何事情:'int(..)'返回它的參數轉換爲一個整數,它不影響它的參數。 – huon 2012-04-21 06:15:14
你爲什麼要使用遞歸?在這裏似乎並不需要。這是作業嗎? – Shep 2012-04-21 06:27:51