2021-08-26 Python之图书管理系统

#图书管理系统

#持久化保存:文件

 1 #用户注册
 2 def register():
 3     username=input('输入用户名:')
 4     password=input('输入密码:')
 5     repassword=input('输入确认密码:')
 6 
 7     if password==repassword:
 8         #保存信息
 9         with open (r'e:\book\users.txt','a') as wstream:
10             wstream.write('{} {}\n'.format(username,password))
11 
12         print('用户注册成功')
13     else:
14         print('密码不一致')
15 
16 #用户登录
17 def login():
18     username=input('输入用户名:')
19     password=input('输入密码:')
20 
21     if username and password:
22         with open(r'e:\book\users.txt') as rstream:
23             while True:
24                 user=rstream.readline()
25                 if not user:
26                     print('用户名或密码输入有误')
27                     break
28                 
29                 input_user='{} {}\n'.format(username,password)
30 
31                 if user==input_user:
32                     print('用户登录成功')
33                     break
34 
35 
36 #展示图书
37 
38 def show_books():
39     print('----------图书馆的图书----------')
40     with open(r'e:\book\books.txt') as rstream:
41         books=rstream.readlines()
42         for book in books:
43             print(book,end='')
44             
45 #register()
46 login()
47 show_books()

 

posted @ 2021-08-26 14:35  admin-xiaoli  阅读(264)  评论(0编辑  收藏  举报