class Car:
def __init__(self, brand, number, owner):
self.brand = brand
self.number = number
self.owner = owner
def read_cars(filename):
cars = []
with open(filename, 'r') as file:
for line in file:
brand, number, owner = line.strip().split()
cars.append(Car(brand, number, owner))
return cars
def find_by_brand(cars, search_brand):
result = []
for car in cars:
if car.brand == search_brand:
result.append((car.owner, car.number))
return result
def count_by_brand(cars):
brands = {}
for car in cars:
brands[car.brand] = brands.get(car.brand, 0) + 1
return brands
def main():
cars = read_cars('X.txt')
search_brand = input("Введите марку автомобиля: ")
owners = find_by_brand(cars, search_brand)
print(f"\nВладельцы автомобилей марки {search_brand}:")
for owner, number in owners:
print(f"Владелец: {owner}, Номер: {number}")
counts = count_by_brand(cars)
print("\nКоличество автомобилей каждой марки:")
for brand, count in counts.items():
print(f"{brand}: {count}")
if __name__ == "__main__":
main()
а) фамилии владельцев и номера автомобилей данной марки;
б) количество автомобилей каждой марки.
просьба не скидывать ответы с чат гпт,они работают но не совсем корректно)
буду сильно благодарен за помощь! =)