如有错误欢迎大家指出,新手初来乍到。程序没那么复杂,是最简单的。
一、需求
编写登录文件 .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:")
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验证结果