python学习之路-用户登录作业练习

设计一个用户登录程序,如果输入错误三次就把用户名写入到一个文件中

代码如下:

# -*- coding:utf-8 -*-
#用户登录系统
username = "abc"
passwd = "1234"
count =0
while count < 3:
    _username = str(input("请输入用户名:"))
    _passwd = str(input("请输入密码a:"))
    if _username == username and _passwd == passwd :
        print("欢迎登录")
        break
    else:
        if count < 2:
            print("输入错误,请检查后再一次输入")
        else:
            print("由于你输入的错误次数过多,登录已经被锁定")
    count += 1
    if count == 3:
        f =open("lock.txt","a",encoding="utf-8")
        f.write("\n")
        f.write(_username)

你可能感兴趣的:(python)