"""
任务:给定了一个 Dog 类,类中有 foot、weight 和 height 三个属性。请在类的外部输出这三个属性的值。
"""classAnimal:
foot =4
weight =14
height =30# 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码########## Begin ########### 第1步:实例化类
d=Animal()# 第2步:输出三个类属性的值print("foot属性值为:%d"%d.foot)print("weight属性值为:%dkg"%d.weight)print("height属性值为:%dcm"%d.height)########## End ##########
练习-Python面向对象之类的定义和使用
"""
任务:定义一个 Math 类,在类中定义一个 mean 方法,传入的参数为一个列表,该方法的作用是计算列表内所有元素的平均值。
"""# 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码########## Begin ########### 定义 Math 类,并在类中定义 mean 方法classMath:defmean(self,list1):
self.list1=list1
a=0for i in self.list1:
a=i+a
return(a*1.0)/len(self.list1)########## End ########### 实例化类
x = Math()
list1 =eval(input())print("平均值为",x.mean(list1))