执行童年时,如何获得童年不带任何参数,但是当我删除字符串q中的school时,就会出现NameError

问题描述

当我用q =童年(学校)执行此代码时,我没有童年不带任何参数 但是当我没有执行它时,他们会说没有定义智能 我试图使__init(自我,聪明)来解决它,但只会使情况变得更糟。 所以我想知道这段代码在做错什么吗?

from ex45f import live
class childhood(live):

    def development(self):
        intelligent["low","average","high"]
        if random.choice(intelligent) == low:
            return "You are dumb"
        elif random.choice(intelligent) == average:
            return "You are average"
        else:
            return "You are smart"

        if school == "yes" and intelligent == high:
            return 'You will have an fantastic life'
        elif school == "no" and intelligent == high:
            return "You will have an average life"
        elif school == "maybe" and intelligent == high:
            return "You will have an good life"
        elif school == "yes" and intelligent == average:
            return "You will have an good life"
        elif school == "no" and intelligent == average:
            return "You will have an bad life"
        elif school == "maybe" and intelligent == average:
            return "You will have an average life"
        elif school == "yes" and intelligent == low:
            return "You will have an average life"
        elif school == "no" and intelligent == low:
            return "You will have an horrible life"
        else:
            return "You will have an bad life"
#Zoek op how random choice antwoord bij betrekt
like_school = """Do you like school?
Possible answers: yes,no or maybe
> """
school = input(like_school)
q = childhood(school)
q.development()

解决方法

确保您在类中作为超类传递的是一类,并创建一个构造函数( init ),并将其作为必需参数,如self和school,并将school分配给self.school并使用它在开发课程中。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...