练习:利用函数实现一个注册系统

def register():
    print("欢迎进入注册系统".center(30,"-"))
    while 1:
        user_name = input("请输入姓名:").strip()
        user_pwd = input("请输入密码:").strip()

        if user_name == "" or user_pwd == "":
            print("用户名或密码不正确,请重新输入")
            continue

        #校验用户名是否存在
        f = open("user_info",mode="r+",encoding="utf-8")
        for line in f: #alex@@123
            if user_name == line.split("@@")[0]:
                print("该用户名已经存在,请重新输入")
                break  #跳出while循环

        else:
            f.write("\n"+user_name+"@@"+user_pwd)  #需要有"\n"换行符 防止添加的信息都写到一行
            f.flush()
            f.close()
            print("注册成功")
            return
register()

 

posted on 2018-08-10 16:30  KD_131  阅读(175)  评论(0编辑  收藏  举报