找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2264|回复: 1

[求助] Python初学者求助

1

主题

1

帖子

1

积分

贫民

积分
1
taobro 发表于 2019-7-10 18:54:39 | 显示全部楼层 |阅读模式
本人阅读埃里克.马瑟斯的《Python编程:从入门到实践》自学中,现正在学习第9章类,其中有一道习题,奈何检查了N遍还是理解不了错误,特求助:

class User():
   
    def __init__(self,first_name,last_name,gender,age):
        self.first_name=first_name
        self.last_name=last_name
        self.gender=gender
        self.age=age
        self.login_attempts=0
   
    def describe_user(self):
        print("The user's name is "+self.first_name.title()+" "+
            self.last_name.title()+", "+self.gender+","+str(self.age)+
            " years old.")
   
    def greet_user(self):
        print("How have you been, Mr "+self.last_name.title()+"?")
   
    def increment_login_attempts(self):
        self.login_attempts+=1
        print("You have attempted to log in "+
            str(self.login_attempts)+" time(s).")
   
    def reset_login_attempts(self):
        self.login_attempts=0
        print("\t"+str(self.login_attempts))
        
class Privilege():
   
    def __init__(self,privileges=['can add post','can delete','can ban user']):
        self.privileges=privileges
   
    def show_privileges(self):
        print("The user "+self.first_name.title()+" "+self.last_name.title()
            +" has the privilege of:")
        for self.privilige in self.priviliges:
            print('\t'+self.privilege.title())

class Admin(User):
    def __init__(self,first_name,last_name,gender,age):
        super().__init__(first_name,last_name,gender,age)
        self.power=Privilege()

taobro=Admin('tao','xu','male',100)
taobro.admin.show_privileges()

Traceback (most recent call last):
  File "9-8.py", line 44, in <module>
    taobro.admin.show_privileges()
AttributeError: 'Admin' object has no attribute 'admin'


回复

使用道具 举报

0

主题

3

帖子

3

积分

贫民

积分
3
IceBear 发表于 2019-7-12 11:08:07 | 显示全部楼层
Admin里没有admin属性啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表