StudyRepo_Synergy/part2_OOP/lesson3/cars.py

30 lines
780 B
Python

from datetime import datetime as dt
class Car:
def __init__(self, **kwargs) -> None:
self.make = kwargs.get("make")
self.model = kwargs.get("model")
self.year = kwargs.get("year")
def display_info(self):
return (x for x in (self.make, self.model, self.year) if x is not None)
def calculate_age(self):
if self.year is None:
return "Неизвестно"
return dt.today().year - self.year
cars = (
Car(make="Ваз", model="Нива", year=2000),
Car(make="Mitsubishi", model="Colt", year=2007),
Car(make="Газ", model="Вогла"),
Car(make="БРДМ", year=1993),
)
for car in cars:
print(*car.display_info())
print("возраст тс:", car.calculate_age())
print()