class Vehicle: ''' The class blueprint for creating Vehicle objects. ''' def __init__(self, make, color, tank=20): ''' Create a new Vehicle Object with these attributes: make: string representing make of the vehicle color: string tank: size of gas tank in gallons curr_gas: current amount of gas in tank in gallons ''' self.model = make self.color = color self.tank = tank self.curr_gas = 0 def add_gas(self, gallons): '''Add gallons to tank. Until it is full''' print("Adding", gallons, "to", self.curr_gas, "currently in tank.") self.curr_gas += gallons if self.curr_gas > self.tank: print('The gas tank is full!') # curr_gas cannot be more than the size of the gas tank. self.curr_gas = self.tank else: print('The gas tank needs', self.tank - self.curr_gas, 'more gallons') def __str__(self): '''Magic method to represent a Vehicle as a string''' return ("Make: " + self.model + ", Color: " + self.color + ", Tank Capacity: " + str(self.tank) + ", Current Gas: " + str(self.curr_gas)) # return 'Gas remaining: ' + str(self.curr_gas) if __name__ == '__main__': my_car = Vehicle('Honda', 'White') your_motorcycle = Vehicle('Mazda', 'Red', 5) truck = Vehicle('Mercedes', 'Black', 30) print("my_car:", my_car) print("your_motorcycle:", your_motorcycle) print("truck:", truck) print() print("**Adding 15 gallons to my_car") my_car.add_gas(15) print("**Adding 30 gallons to your_motorcycle") your_motorcycle.add_gas(30) print() print("my_car:", my_car) print("your_motorcycle:", your_motorcycle) print("truck:", truck)