【发布时间】:2016-08-11 09:58:15
【问题描述】:
程序需要允许用户 3 次错误的尝试写入密码。但是,如果他们的密码尝试正确,我希望程序打印“nice”。
这是我目前所拥有的:
def main():
n = 2
for i in range(0, 3, 1):
attempt = input('Enter password: ')
if attempt != 'password':
print('Incorrect. ' + str(n) + ' attempts left')
n = int(n) - 1
else:
print('nice')
【问题讨论】:
-
您要查找的单词是
break。