此代码的前提是要求输入名称,最多尝试3次。将if语句添加到while循环
password = 'correct'
attempts = 3
password = input ('Guess the password: ')
while password != 'correct' and attempts >= 2:
input ('Try again: ')
attempts = attempts-1
if password == 'correct': #Where the problems begin
print ('Well done')
我只能输入正确的密码,第一次尝试返回'做得好'。在另外两次尝试中,它会返回为“再次尝试”。如果输入任何尝试,我怎样才能让它恢复得很好?
仅供参考,'企图=企图-1'可以更简单地写为'企图 - = 1' – Alexander