sunchenxi

导航

实验7 类和模块

 1 class User:
 2     def __init__(self,name="guest",password="111111",status="1"):
 3         self.name=name
 4         self.password=password
 5         self.status=status
 6     def info(self):
 7         print(self.name)
 8         print(self.password)
 9         if self.status=='1':
10             print('正常账户')
11         else:
12             print('封禁账户')
13     def modify_password(self):
14         i=0
15         while True:
16             old_password = input('输入旧密码:')
17             if old_password == self.password:
18                 new_password = input('输入新密码:')
19                 print('修改密码成功')
20                 break
21             elif old_password != self.password:
22                 i += 1
23                 if i == 3:
24                     print("账户已锁,请稍后再试")
25                     break
26 class Admin(User):
27     def __init__(self,name="admin",password="999999",status='1'):
28         self.name=name
29         self.password=password
30         self.status=status
31     def info(self):
32         print(self.name)
33         print(self.password)
34         if self.status == '1':
35             print('正常账户')
36         else:
37             print('封禁账户')
38     def reset_password(self,user):
39         user.password="111111"
40     def ban_user(self,user):
41         user.status='0'
42     def unblock_user(self,user):
43         user.status='1'
44 
45 
46 
47 u1=User("sancy","123456","1")
48 u2=User("Bob","021121",'0')
49 u1.info()
50 u2.info()
51 u1.modify_password()
52 a1=Admin('Karry','666666','1')
53 a1.info()
54 a1.reset_password(u1)
55 u1.info()
56 a1.ban_user(u1)
57 u1.info()
58 a1.unblock_user(u2)
59 u2.info()
 1 from user import User,Admin
 2 
 3 u1=User("Amy","123456","1")
 4 u2=User("Bob","021121",'0')
 5 u1.info()
 6 u2.info()
 7 u1.modify_password()
 8 a1=Admin('Karry','666666','1')
 9 a1.info()
10 a1.reset_password(u1)
11 u1.info()
12 a1.ban_user(u1)
13 u1.info()
14 a1.unblock_user(u2)
15 u2.info()

 

posted on 2022-06-01 17:28  靠谱一星  阅读(31)  评论(1编辑  收藏  举报