Advertisement

[Python](8) #面向对象练习题

阅读量:

创建一个汽车类(Car),其属性包括颜色、品牌、车牌号和价格。然后创建两个实例对象,并为这些属性赋值。最后输入这些属性的值。

复制代码
    class car():
    def __init__(self,color,brand,plate,price):
        self.color = color
        self.brand = brand
        self.plate = plate
        self.price = price
    def driver(self):
        print(self.color,self.brand,self.plate,self.price)
    c = car("红色","奔驰","黑A00000",15000000)
    c.driver()

请创建一个名为Player的类,并在其内部定义身高属性、体重属性以及名称属性;随后,请创建两个Player实例命名为YaoMing和KobeBryant;这两个实例将分别代表著名的中国篮球运动员姚明和他的美国篮球巨星科比·布莱恩特。

复制代码
    class player():
    def __init__(self,high,weight,name):
        self.high = high

全部评论 (0)

还没有任何评论哟~