#نوع المنتج على مستوى الكلاس
class Car :
type = "Vehicle"
def __init__(self, id, model, price,color ,mileage ) :
self.id = id
self.model = model
self.price = price
self.color = color
self.mileage = mileage
def discount (self,ratio):
self.price = self.price - self.price * ratio
def reset_mileage (self):
self.mileage = 0
def add_mileage(self,km):
if km <= 0 :
print ("The added distance must be greater than zero!")
else :
self.mileage += km
def show_details (self):
print (f"type: {Car.type}")
print (f"ID : {self.id}")
print (f"Model: {self.model}")
print (f"Price: {self.price}")
print (f"Color: {self.color}")
print (f"Mileage: {self.mileage}")
#انشاءالسيارات
car_1 = Car (id = 1, model = "Toyota Corolla", price = 500000 , color = "White Corolla" ,mileage = 20000)
car_2 = Car (id = 2,model = "BMW M5", price = 12000000, color= "Black BMW" , mileage= 10000)
car_1.show_details()
car_2.show_details()
#زيادة المسافة
car_1.add_mileage(500)
print ("The distance after the increase:",car_1.mileage)
#تصفير العداد
car_1.reset_mileage ()
print ("The distance after reset",car_1.mileage)