enter code hereclass Car():
'''一次模拟汽车的简单尝试'''
def __init__(self,make,model,year,mileage):
'''初始化描述汽车的属性'''
self.make = make
self.model = model
self.year = year
self.updata_odometer(mileage)
# self.odometer_reading = 0
# self.mileages = mileage
#用于外部调动
def get_reading(self):
return self.odometer_reading
#用于修改私有属性
def updata_odometer(self,mileage):
if mileage >= ():# 这里调用谁?
self.odometer_reading = mileage
else:
print("You can't roll back an odometer!")
def get_descriptive_name(self):
'''返回整洁的描述性信息'''
long_name = str(self.year + " " + self.make + " " + self.model )
return long_name.title()
def read_odometer(self):
'''打印一条支持汽车里程的消息'''
print("This car has " + str(self.odometer_reading) + " miles on it.")
my_new_car = Car("audi","a4","2016",12) print(my_new_car.get_descriptive_name()) my_new_car.updata_odometer(23) my_new_car.read_odometer() my_new_car.updata_odometer(33) my_new_car.read_odometer()
my_new_car.updata_odometer(13) my_new_car.read_odometer()