实验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 if self.status==1: 8 print(self.name,self.password,'账户正常') 9 else: 10 print(self.name,self.password,'账户被封禁') 11 12 def modify_password(self): 13 old=eval(input('请输入旧密码:')) 14 if self.password==old: 15 new=input('请输入新密码:') 16 self.password=new 17 print('密码修改成功') 18 else: 19 count=2 20 while old!=self.password: 21 if count>0: 22 old=eval(input('请再次输入旧密码:')) 23 if old==self.password: 24 self.password=eval(input('请输入新密码')) 25 self.ststus=1 26 27 print('密码修改成功') 28 29 break 30 if old!=self.password: 31 count=count-1 32 else: 33 self.status=0 34 print('账户已锁,请稍后再试') 35 break 36 class Admin(User): 37 def __init__(self,name='admin',password=999999,status=1): 38 self.name=name 39 self.password=password 40 self.status=status 41 def info(self): 42 if self.status==1: 43 self.status='账户正常' 44 else: 45 self.status='账户被封禁' 46 print('管理员账户:') 47 print(self.name,self.password,self.status) 48 def reset_password(self,user): 49 user.password=eval(input('请输入你要重置的密码:')) 50 def ban_user(self,user): 51 user.status=0 52 def unlock_user(self,user): 53 user.status=1 54 55 56 u1=User() 57 u1.info() 58 u1.modify_password() 59 u1.info() 60 a1=Admin() 61 a1.reset_password(u1) 62 a1.ban_user(u1) 63 u1.info() 64 a1.unlock_user(u1) 65 u1.info()
1 from user import User,Admin 2 u1=User() 3 u1.info() 4 u1.modify_password() 5 u1.info() 6 7 a1=Admin() 8 a1.info() 9 10 a1.reset_password(u1) 11 a1.ban_user(u1) 12 u1.info() 13 a1.unlock_user(u1) 14 u1.info()
标签:status,info,self,u1,实验,user,模块,password 来源: https://www.cnblogs.com/day-day/p/16347772.html