Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LaRevoltage/6e8238dcf52b48a6980ad0b2a4c47c14 to your computer and use it in GitHub Desktop.
Save LaRevoltage/6e8238dcf52b48a6980ad0b2a4c47c14 to your computer and use it in GitHub Desktop.
class Auto:
auto_count = 0
user_car = []
cars = []
check_exist = False
def __init__(self, model,year, price):
self.model = model
self.year = year
self.price = price
Auto.auto_count += 1
Auto.cars.append(self)
def print_count():
print(f"there are {Auto.auto_count} cars in our store")
def find_car_by_year (user_needs_year):
for i in Auto.cars:
if i.year == user_needs_year:
Auto.user_car.append(i)
else:
return( f"there is no car {2022 - int(user_needs_year)} age in our store")
return(Auto.user_car)
#print(f"the rice for model {i.model} {i.year} year is {i.price} USD")
# Auto.check_exist = True
user_needs_year = "1999"
car1 = Auto("VW","1999",2300)
car2 = Auto("BMV","1999",5200)
car3 = Auto("Audi","1998",4500)
Auto.print_count()
Auto.find_car_by_year(user_needs_year)
result_search = Auto.find_car_by_year(user_needs_year)
print("There are following cars with requested age:")
for i in result_search:
print(i.model, i.year, i.price)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment