每天努力一点点,坚持下去 ------ 博客首页

Python-注册

import time

users = {}
time = time.strftime('%Y-%m-%d %H:%M:%S')
with open('user.txt')as fr:
    for line in fr:
        if line.strip():
            user,password = line.split(',')
            users[user] = password
while True:
    username = input('请输入账号:').strip()
    password = input('请输入密码:').strip()
    cwd = input('请再次输入密码:').strip()

    if username=='' and password=='' and cwd=='':
        print('不能为空')
        continue
    elif username in users:
        print('账户已存在')
        continue
    elif password != cwd:
        print('两次密码输入不一致')
        continue
    elif len(password)<6 or len(password)>13:
        print('密码长度需要是大于6位小于13位')
        continue
    else:
        users[username] = password
        print('%s注册成功,今天的时间是%s'%(username,time))
        break

with open('user.txt','a+')as fw:
    for i in users:
        p = ('%s,%s\n'%(i,users.get(i)))
        fw.writelines(p)

 

posted @ 2020-03-28 17:25  他还在坚持嘛  阅读(253)  评论(0编辑  收藏  举报