有谁可以帮我看看这个继承的代码怎么改啊
tips = '''***********************************
让我们来看看大人和小孩是分别是如何表达生气的
***********************************
'''
adult_list = []
children_list = []
def add():
global adult_list
name = input("请输入名字:")
age = int(input("请输入年龄:"))
think = input("请输入生气还是高兴:")
if age>30:
adult = Adult(name = name,age = age, think=think)
adult_list.append(adult)
if age<18:
children = Children(name=name, age=age, think=think)
adult_list.append(children)
class human_beings:
def __init__(self,name,age,think):
self.name = name
self.age = age
self.think = think
class Adult(human_beings):
def __init__(self,name,age,think):
super().__init__(name=name,age=age,think=think)
self.type_ = '大人'
def abuse(self):
print(f"{self.name}是一个{self.age},他(她)想 {self.think},所以他(她)说GUN")
class Children(Adult):
def __init__(self, name, age, think):
super().__init__(name=name, age=age, think=think)
self.type_ = '小孩'
def abuse(self):
print(f"{self.name}是一个{self.age},他(她)想 {self.think},所以他(她)说:哼,我真的生气了")
def act(self):
print("还打滚")
while True:
print(tips)
add()
adult_list.abuse()
children_list.abuse()
本帖最后由 小凯2013 于 2022-7-24 09:11 编辑
温馨提醒:请使用代码格式发布代码。
adult_list = []
children_list = []
class Human_beings: #类名首字母要用大写。
def __init__(self,name,age,think):
self.name = name
self.age = age
self.think = think
class Adult(Human_beings):
def __init__(self,name,age,think):
super().__init__(name=name,age=age,think=think)
self.type_ = '大人'
def abuse(self):
print(f"{self.name}是一个{self.age},他(她)想 {self.think},所以他(她)说GUN")
class Children(Adult):
def __init__(self, name, age, think):
super().__init__(name=name, age=age, think=think)
self.type_ = '小孩'
def abuse(self):
print(f"{self.name}是一个{self.age},他(她)想 {self.think},所以他(她)说:哼,我真的生气了")
def act(self):
print("还打滚")
def add(): #顺序别弄反了。
global adult_list
name = input("请输入名字:")
age = int(input("请输入年龄:"))
think = input("请输入生气还是高兴:")
if not age < 18 : #注意这里,不然输入19就完蛋了。
adult = Adult(name = name,age = age, think=think)
adult_list.append(adult)
if age < 18:
children = Children(name=name, age=age, think=think)
adult_list.append(children)
页:
[1]