Почему мой tripssincemaintenence выводит 1 вместо 99 в классах Python?

#python #python-requests

#python #python-запросы

Вопрос:

Я использую Python 3. Вот как выглядит мой класс и класс наследования:

 class Vehicle:
    def __init__(self,Make,Model,Year,Weight,TripsSinceMaintenance = 0,NeedsMaintenance = False):
        self.make = Make
        self.model = Model
        self.year = Year
        self.weight = Weight
        self.needsmaintenance = NeedsMaintenance
        self.tripssincemaintenance = TripsSinceMaintenance
    def repair(self):
        self.needsmaintenance = True
        self.tripssincemaintenance = 0

class Cars(Vehicle):
    def __init__(self,Make,Model,Year,Weight,TripsSinceMaintenance = 0,NeedsMaintenance = False,isdriving = False):
        Vehicle.__init__(self,Make,Model,Year,Weight,TripsSinceMaintenance = 0,NeedsMaintenance = False)
        self.isDriving = isdriving
    def Drive(self):
        self.isDriving = True
        
    def Stop(self):
        self.isDriving = False
        self.tripssincemaintenance  = 1
        if self.tripssincemaintenance == 100:
            self.needsmaintenance = True
 

Здесь я использую класс:

     Car2 = Cars("Mercedes","G-Wagon","2016","2000", 98,False)
    Car2.Drive()
    Car2.Stop()
    print(Car2.year)
    print(Car2.model)
    print(Car2.make)
    print(Car2.isDriving)
    print(Car2.needsmaintenance)
    print(Car2.tripssincemaintenance)
    print(Car2.weight)
 

Проблема в том, что при печати self.tripssincemaintenance отображается 1 вместо 99. Почему это? TIA

Комментарии:

1. Вы устанавливаете 0 значение TripsSinceMaintenance при инициализации конструктора суперкласса. (строка 17)