I keep getting a NameError
stating that CarInventory
is not defined, as well as highest. Also, I am still not sure if my code for the method compare() is actually right.
This is my code for the assignment:
class CarInventory():
def __init__(self, n_cars = 0, cars = []):
self.n_cars = n_cars
self.cars = cars
def add_car(manufacturer,model,year,mpg):
self.cars = {'manufacturer': self.manufacturer, 'model': self.model, 'year': self.year, 'mpg': self.mpg}
self.n_cars = self.n_cars + 1
def compare(self, attribute, direction=highest):
self.lowest = self.cars[0]
self.direction = self.cars[0]
for car in self.cars:
if self.car[attribute] < self.lowest:
self.lowest = car
elif self.car[attribute] > self.highest:
self.highest = car
if direction == highest:
output = highest
elif direction == lowest:
output = lowest
return output