class Vehicle: ''' The class blueprint for creating Vehicle objects. ''' def __init__(self, make, color, passengers, wheels=4, tank=20): ''' Create a new Vehicle Object make: string representing make of the vehicle color: string passengers: int for max number of passengers. ''' self.model, self.color, self.wheels = make, color, wheels self.seats = passengers self.gas = 0 self.tank = tank def fill_tank(self, gallons): '''Add gallons to tank. Until it is full''' self.gas += gallons if self.gas > self.tank: print 'The gas tank is full!' self.gas = self.tank else: print 'The gas tank needs', self.tank - self.gas, 'more gallons' def __str__(self): '''Magic method to represent a Vehicle as a string''' return 'Gas remaining: ' + str(self.gas) def __hash__(self): ''' Magic method to make a vehicle hashable ''' return hash(self.model) + hash(self.color) + hash(self.seats) + \ hash(self.wheels) + hash(self.tank) + hash(self.gas) if __name__ == '__main__': my_car = Vehicle('Honda', 'White', 4) your_motorcycle = Vehicle('Mazda', 'Red', 2, 2) semi = Vehicle('Mercedes', 'Black', 2, wheels=16) print my_car print your_motorcycle print semi my_car.fill_tank(15) your_motorcycle.fill_tank(30)