build_in_eror

PHOTO EMBED

Thu Mar 04 2021 08:49:01 GMT+0000 (Coordinated Universal Time)

Saved by @Bartok #python

class Car:
  def __init__(self,make,model):
    self.make =make
    self.model = model

  def __repr__(self):
    return f'<car {self.make} {self.model}>'


class Garage:
  def __init__(self):
    self.cars = []
    
  def __len__(self):
      return len(self.cars)
  
  def add_car(self,car):
    if not isinstance(car,Car):# accept only clss obcject clas car
      raise TypeError(f'Tried to add `car.__class__.__name__ to the garage but you can only add car object')
    self.cars.append(car)
    #raise NotImplemented('We cant add catss to the garage yet')# you create a new error of type notimplemented error 



ford =Garage()
car = Car('Ford','Fiesta')

ford.add_car(car)
print(len(ford))
content_copyCOPY