python循环使⽤while或for语句实现⽤户名密码输错三次退出如有错误欢迎⼤家指出,新⼿初来乍到。程序没那么复杂,是最简单的。
⼀、需求
编写登录⽂件 .py
1. 输⼊⽤户名密码
2. 正确,输出欢迎登录
3. 当输⼊⽤户名和密码⼩于 3 次,输⼊⽤户名或者密码错误,提⽰⽤户名或者密码错误。再次输⼊⽤户名和密码,剩余输⼊次
数。
3. 当输错三次后退出
⼆、流程图
三、代码
for
#!/usr/bin/env python
#_*_conding:utf-8_*_
user = "zhangjinglei"
password = "lei100103"
count = 0;
for i in range(3):
username = input("username:")while语句怎么用在python中
password = input("password:")
if username == user and password == password:
print("Welcome Login")
count = 3
break
else:
print("Wrong username or password")
count += 1
print("you can try", 2 - i, "times")
while
#!/usr/bin/env python
#_*_conding:utf-8_*_
user = "zhangjinglei"
password = "lei100103"
count = 0;
while count < 3:
username = input("username:")
password = input("password:")
if username == user and password == password:
print("Welcome Login")
count = 3
else:
print("Wrong username or password")
count += 1
print("you can try", 3 - count, "times")
四、验证结果
1.for 验证结果
2.whlie验证结果

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。