Python学习之路—6

基于文件的注册和登录

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 #Author Wu
 4 
 5 # 注册:
 6 
 7 username = input('请输入用户名:')
 8 passwd = input('请输入密码:')
 9 
10 f = open('user.txt','r+',encoding='utf-8')
11 f.read()
12 f.write('\n%s' %(username.strip()))
13 f.write('|')
14 f.write(passwd.strip())
15 f.close()
16 print('注册成功!!!')
17 
18 #登录
19 username = input('请输入用户名:')
20 passwd = input('请输入密码:')
21 
22 f = open('user.txt','r+',encoding='utf-8')
23 while True:
24     data = f.readline()
25     user, pwd = data.split('|')
26     if username == user.strip() and passwd == pwd.strip():
27         print('用户名和密码正确')
28         break
29     else:
30         continue
View Code

 

posted @ 2017-08-24 19:39  流星之泪  阅读(80)  评论(0)    收藏  举报