lingcooo 2021-10-27 21:45 采纳率: 90.9%
浏览 17
已结题

实在找不出哪里缩进有问题


class User(): 
     """用户信息及描述"""
    def __init__(self, first_name, last_name, sex): 
        self.first = first_name
        self.last = last_name
        self.sex = sex
        self.login_attempts = 0
        
    """打印用户信息"""
    def describe_user(self): 
        print('\nName: ' + self.first.title() + 
                    self.last.title(), '\nSex: ' + self.sex)
                        
    """打印问候语"""
    def greet_user(self): 
        if self.sex == 'man': 
            print('\nMr. ' + self.first.title() + 
                    ' Welcome to the python.')
        else: 
            print('\nMis. ' + self.first.title() + 
                    ' Welcome to the python.')
    
    """尝试次数统计"""
    def increment_login_attempts(self):
        self.login_attempts += 1
    
    """重置尝试次数"""
    def reset_login_attempts(self): 
        if login_attempts != 0 
            login_attempts    == 0
                        

class Admin(User): 
    """管理员用户信息"""
    def __init__(self, first_name, last_name, sex): 
        """初始化父类"""
        super().__init__(first_name, last_name, sex)
        self.privileges = ["can add post", 
                                "can delete post", "can ban user"]
    
    """显示管理员权限"""
    def show_privileges(self): 
        for pri in self.privileges: 
            print('\n - ' + pri.titler())
    
    liu = Admin('li', 'qiang', 'man')
    liu.show_privileges()
    

提示错误是:


File "/private/var/mobile/Containers/Shared/AppGroup/106E91C2-1881-478A-9069-7F89CF8A559C/Pythonista3/Documents/练习用.py", line 4
    def __init__(self, first_name, last_name, sex):
                                                   ^
IndentationError: unindent does not match any outer indentation level

  • 写回答

1条回答 默认 最新

  • 辉煌仪奇 2021-10-27 21:56
    关注

    你好,你的程序的错误的地方有几处,我就不一一说了,直接将修改好的代码发给你,你对比一下就知道了,

    
    
    class User():
        """用户信息及描述"""
    
        def __init__(self, first_name, last_name, sex):
            self.first = first_name
            self.last = last_name
            self.sex = sex
            self.login_attempts = 0
    
        """打印用户信息"""
    
        def describe_user(self):
            print('\nName: ' + self.first.title() +
                  self.last.title(), '\nSex: ' + self.sex)
    
        """打印问候语"""
    
        def greet_user(self):
            if self.sex == 'man':
                print('\nMr. ' + self.first.title() +
                      ' Welcome to the python.')
            else:
                print('\nMis. ' + self.first.title() +
                      ' Welcome to the python.')
    
        """尝试次数统计"""
    
        def increment_login_attempts(self):
            self.login_attempts += 1
    
        """重置尝试次数"""
    
        def reset_login_attempts(self):
            if self.login_attempts != 0:
                self.login_attempts == 0
    
    
    class Admin(User):
        """管理员用户信息"""
    
        def __init__(self, first_name, last_name, sex):
            """初始化父类"""
            super().__init__(first_name, last_name, sex)
            self.privileges = ["can add post",
                               "can delete post", "can ban user"]
    
        """显示管理员权限"""
    
        def show_privileges(self):
            for pri in self.privileges:
                print('\n - ' + pri.title())
    
    
    liu = Admin('li', 'qiang', 'man')
    liu.show_privileges()
    

    运行结果

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月4日
  • 已采纳回答 10月27日
  • 创建了问题 10月27日

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改