为了账号安全,请及时绑定邮箱和手机立即绑定

三次尝试的 Python 密码

三次尝试的 Python 密码

一只萌萌小番薯 2022-06-22 17:52:41
我只是创建了一个密码验证过程。该程序要求用户输入密码;他们有三个尝试。如果他们没有更正,请让他们再试一次。它只是无法正常运行。如果我输入“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


查看完整回答
反对 回复 2022-06-22
  • 1 回答
  • 0 关注
  • 142 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号