码迷,mamicode.com
首页 > 其他好文 > 详细

程序练习(2)

时间:2018-03-12 22:57:42      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:splay   pos   write   ext   锁定   学费   程序   学校   添加   

1.用户锁定程序

要求:1.将用户名和密码存在一个文件中;

      2.当用户名不匹配时,询问用户是否新建账号;

   3.用户输入密码错误三次,将用户名移入锁定文件中,不得登录;

      4.管理员可查看各账号文件,并且可以选择是否将锁定的用户移出锁定文件。(暂时没有实现)

技术分享图片
 1 #user:{"seller":123456, "buyer":112233}
 2 #locked_user:{‘seller‘: 123456}
 3 
 4 username = input("username:")
 5 count = 0
 6 with open("user", "r") as f1, open("locked_user", "r") as f2:
 7     user_info = eval(f1.read())
 8     locked_info = eval(f2.read())
 9     if username in locked_info.keys():  #首先判断用户名是够被锁定
10         print("\033[31;1mYou have been locked!\033[0m")
11     else:
12         if username in user_info.keys():  #判断用户名是否已经注册
13             while True:
14                 psword = input("password:")
15                 if psword.isdigit():  # 判断是否是整数形式
16                     psword = int(psword)
17                 if psword == user_info[username]:
18                     print("\033[31;1mlog in...\033[0m")
19                     exit()
20                 else:
21                     print("\033[41;1mPlease try again!\033[0m")
22                 count += 1
23                 if count == 3:
24                     print("\033[41;1mNo more time!\033[0m")
25                     with open("locked_user", "w") as f3:
26                         locked_info[username] = user_info[username]
27                         f3.write(str(locked_info))
28 
29         else:
30             choice = input("Would you want to create new one?")
31             if choice == yes:
32                 _username = input("Username: ")
33                 _psword = input("Password: ")
34                 if len(_username) and len(_psword):  #判断是否为空
35                     if _psword.isdigit():     #如果是整数形式,将其转为整数
36                         _psword = int(_psword)
37                     user_info[_username] = _psword   #添加到user_info字典中
38                     with open("user", "w") as f4:
39                         f4.write(str(user_info))
40                 else:
41                     print("\033[31;1mInvide input!\033[0m")
42             else:
43                 exit()
View Code

2.选课系统(使用类进行实现)

角色:学校、学员、课程、讲师

要求: 1. 创建北京、上海 2 所学校;

    2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开;

    3. 课程包含周期,价格,通过学校创建课程;

    4. 通过学校创建班级, 班级关联课程、讲师;

    5. 创建学员时,选择学校,关联班级;创建讲师角色时要关联学校;

    6. 提供两个角色接口:

    6.1 学员视图, 可以注册, 交学费, 选择班级,

    6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩,

    6.3 管理视图,创建讲师, 创建班级,创建课程;

    7. 上面的操作产生的数据都通过pickle序列化保存到文件里。

 

程序练习(2)

标签:splay   pos   write   ext   锁定   学费   程序   学校   添加   

原文地址:https://www.cnblogs.com/stumn/p/8527667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!