請教一下, updata_odometer方法中我呼叫誰可以對上一個mileage 進行比較

longlong123發表於2020-06-20
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()

相關文章