python编程从入门到实践同步练习给子

北京中科癜风医院好嘛 https://yyk.familydoctor.com.cn/2831/detail/

1.管理员:管理员是一种特殊的用户。编写一个名为Admin的类,让它继承你为编写的User类。添加一个名为privileges的属性,用于存储一个由字符串(如canaddpost等)组成的列表。编写一个名为show_privileges()的方法,它显示管理员的权限。创建一个Admin实例,并调用这个方法。

classUser():

def__init__(self,login_attempts):

self.login_attempts=login_attempts

defincrement_login_attempts(self,login_attempts):

self.login_attempts+=1

iflogin_attempts=self.login_attempts:

self.login_attempts=login_attempts

print(login_attempts)

else:

print(不能打印该值。)

defreset_login_attempts(self):

login_attempts=0

classAdmin(User):

def__init__(self,login_attempts):

self.login_attempts=login_attempts

super().__init__(login_attempts)

privileges=[]

privileges.append(login_attempts)

defshow_privileges(self):

print(管理员的权限为:+str(self.login_attempts))

my_user=User(1)

my_user.increment_login_attempts(2)

my_user.increment_login_attempts(3)

my_user.reset_login_attempts()

Admin=Admin(cannotpost)

Admin.show_privileges()




转载请注明:http://www.aierlanlan.com/cyrz/4391.html

  • 上一篇文章:
  •   
  • 下一篇文章: 没有了