我只是创建了一个密码验证过程。该程序要求用户输入密码;他们有三个尝试。如果他们没有更正,请让他们再试一次。它只是无法正常运行。如果我输入“Tom”作为密码,它不会进入授予访问权限。此外,在我尝试了两次之后,“尝试三”没有出现。password = 'Tom'count = 0while count <= 3: Question = input('Please enter the password: try1') if Question == password: print('Access granted Pass 1') break while count <= 2: Question = input('That is incorrect, please try again: trytwo') count += 2 while count <= 1 : Question = input('That is incorrect, please try again: trythree') else: print('Access denied') count += 1
1 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
在这种情况下,您错误地使用了 while 循环
password = 'Tom'
count = 1
while count <= 3:
Question = input('Please enter the password: try{}'.format(count))
if Question == password:
print('Access granted Pass {}'.format(count))
break
else:
print("That is incorrect, please try again")
count+=1
if count == 4:
print('Access denied')
count += 1
添加回答
举报
0/150
提交
取消
