三次尝试的 Python 密码

我只是创建了一个密码验证过程。该程序要求用户输入密码;他们有三个尝试。如果他们没有更正,请让他们再试一次。它只是无法正常运行。


如果我输入“Tom”作为密码,它不会进入授予访问权限。此外,在我尝试了两次之后,“尝试三”没有出现。


password = 'Tom'

count = 0

while 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


一只萌萌小番薯
浏览 144回答 1
1回答

陪伴而非守候

在这种情况下,您错误地使用了 while 循环password = 'Tom'count = 1while count <= 3:&nbsp; &nbsp; &nbsp;Question = input('Please enter the password: try{}'.format(count))&nbsp; &nbsp; &nbsp;if Question == password:&nbsp; &nbsp; &nbsp; &nbsp;print('Access granted Pass {}'.format(count))&nbsp; &nbsp; &nbsp; &nbsp;break&nbsp; &nbsp; &nbsp;else:&nbsp; &nbsp; &nbsp; &nbsp;print("That is incorrect, please try again")&nbsp; &nbsp; &nbsp; &nbsp;count+=1if count == 4:&nbsp; &nbsp; &nbsp; &nbsp; print('Access denied')&nbsp; &nbsp; &nbsp; &nbsp; count += 1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python