如何使此代码再次启动while循环,直到用户输入正确的密码
userPassword =input('parola;')
userPasswordId = input('parola')
counter = 0
while userPasswordId != userPassword and counter < 3:
print('Sorry the password is incorect.Try again!')
counter = counter + 1
print('You have', 3 - counter, 'attempts left.')
userPasswordId = input('Enter your password:')
if counter == 3:
print('Your account is locked for 30 seconds!!!!!')
import time
sec = 0
while sec != 5:
print('>>>>>>>>>>>>>>>>>>>>>', sec)
# Sleep for a sec
time.sleep(1)
# Increment the minute total
sec += 1
这叫做异步编程。Python中引入了async和await关键字
只需将
if counter == 3
行及其下的块移到while
循环中为了改进用户看到的消息流,我也对代码进行了一些重构
举个例子:
此代码将继续循环,直到用户输入正确的密码,此时它将
break
执行循环相关问题 更多 >
编程相关推荐