简单的注册登录

username = input('请填写账号>>>')
password = input('请填写密码>>>')
with open('log',mode='w',encoding='utf-8') as f:
    # f.write('账号:' + username + '\n' +'密码:' + password)
    f.write('账号:{}\n密码:{}'.format(username,password))
print('注册成功!')
print('请输入账号密码')

count = 0
while count < 3:
    username = input('账号:')
    password = input('密码:')
    with open('log',mode='r+',encoding='utf-8') as f:
        li = f.readlines()
        # print(li[0][3:])
        # print(li[1][3:])
        count += 1
     #strip,默认可以去空格和换行符 if username == li[0][3:].strip() and password == li[1][3:].strip(): print('登录成功!') break elif count == 3: print('账号密码错误多次!终止输入') break else: print('账号或者密码错误!')

 

posted @ 2019-02-21 12:01  ChenGouDa  阅读(160)  评论(0编辑  收藏  举报