问题描述
当我用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并使用它在开发课程中。