我正在尝试用 Python 编写一个简单的“密码”程序,该程序允许使用递归函数尝试 3 次“登录”。我不明白为什么它不起作用......(是的,受侏罗纪公园启发)
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)
最佳答案
你们很亲密。只有几个小的修复:
def magicWord(count):
answer = raw_input("What is the password? ")
if answer == 'lucas':
print 'ACESS GRANTED'
else:
count += 1
if count > 2:
print "na na na you didn\'t say the magic word. "
return
else:
magicWord(count)
这是一个示例 session :
>>> magicWord(0)
What is the password? alan
What is the password? ellie
What is the password? ian
na na na you didn't say the magic word.
关于python - 如何在 Python 中使用递归计数器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10256675/