python用户名和密码登录三次_Python用户名和密码,3次尝试

这里试试这个(我尽量少修改代码,这样你就可以自己识别相同的逻辑了)print('Enter correct username and password combo to continue')

count = 0

# "" or '' because you are assigning a value string into it

password = ""

username = ""

# looping will continue when wrong input for three times and ask again...

while password!='Hytu76E' and username!='bank_admin' and count < 3:

# you are collecting user input from CLI separately (you can not assign and operator to such operation as per your code ;)

username = input("Enter username: ")

password = input("Enter password: ")

if password=='Hytu76E' and username=='bank_admin':

# if match, grand and break

print('Access granted')

break

else:

print('Access denied. Try again.')

count+=1 # as per gbse, in the comments, you will need the + to count up

代码中的问题:# you are assigning string value, what for? this would make the loop hit positive the first time

password=Hytu76E # string assignment error in syntax, anyway

username=bank_admin # string assignment error in syntax, anyway

# you can not assigning and operator in the input because of no if condition in this line, also you should compare the values of the input

username=input('Enter username: ') and password=input('Enter password: ')

# if code is ok, then move outside the loop in the case when the user enters the first time good answers

if password=='Hytu76E' and username=='bank_admin':

print('Access granted')

else:

print('Access denied. Try again.')

# you are decremented the counter which would never leave teh loop at 4, you should add one on each iteration so count+=1 (count = count + 1)

count-=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值