一、题目
XX网的打工人有基本信息姓名(name)、工号(ID)、签到天数(num),请创建一个Nowcoder类,包括其中基本成员以及初始化方法__init__,并创建打印方法printInformation,该方法内输出类似"NiuNiu's ID is 10001, and his or her number of signing in is 89."的个性化句子,句子中的姓名、工号、天数属于个性化。
同时,XX网还有多部门,比如IT部门基本信息多了使用语言(language),美工部门基本信息多了主色调(color),请创建Nowcoder的子类IT以及Designer,继承Nowcoder的所有成员及初始化方法。
现在分别输入IT部门和美工部门的基本信息,请分别创建IT类和Designer类,并对其初始化,各自调用printInformation后直接输出多余的基本信息。
一行输入一个打工人的四项基本信息,以空格间隔,总共两行。
第一行输出IT部门的printInformation信息,第二行输出IT部门的使用语言。
第三行输出美工部门的printInformation信息,第四行输出美工部门的主色调。
二、代码
#定义一个类
class Nowcoder:
#初始化属性:
def __init__(self,name,ID,num):
#获取属性值
self.name = name
self.ID = ID
self.num = num
#定义打印的方法
def printInformation(self):
#打印
print("%s's ID is %s, and his or her number of signing in is %s."%(self.name,self.ID,self.num))
#定义IT类,继承Nowcoder
class IT(Nowcoder):
#属性
def __init__(self,name,ID,num,language):
#调用父类属性
super(IT,self).__init__(name,ID,num)
#获取属性
self.language = language
#定义美工类,继承Nowcoder
class Designer(Nowcoder):
#定义获取属性方法
def __init__(self,name,ID,num,color):
#继承父类方法
super(Designer,self).__init__(name,ID,num)
self.color = color
#输入参数
a,b,c,d = input().split()
#创建对象
it = IT(a,b,c,d)
#调用printInterfomation方法
it.printInformation()
#获取language
print(it.language)
#以下同理
a,b,c,d = input().split()
de = Designer(a,b,c,d)
de.printInformation()
print(de.color)
三、输入输出展示
输入:
NiuNiu 10001 89 java
NiuMel 10002 77 blue
输出:
NiuNiu's ID is 10001, and his or her number of signing in is 89.
java
NiuMel's ID is 10002, and his or her number of signing in is 77.
blue
因篇幅问题不能全部显示,请点此查看更多更全内容