def add_vehicle(all_vehicles): make = input('Enter make : ') model = input('Enter model : ') color = input('Enter color : ') year = int(input('Enter year : ')) mileage = int(input('Enter mileage : ')) vehicle_id = len(all_vehicles) automobile = Automobile(vehicle_id, make, model, color, year, mileage) print('Vehice added with id : ' + str(vehicle_id)) all_vehicles.append(automobile)
from motor import Motor from automobile import Automobile fl = Motor(4) fr = Motor(17) br = Motor(22) bl = Motor(27) robot = Automobile(fr, br, fl, bl) while True: fl.forward() #robot.drive()
x_change = 0 barrierList = [] joysticks = [] pygame.joystick.init() c = Controller() fl = Motor(4) fr = Motor(17) br = Motor(22) bl = Motor(27) auto = Automobile(fr, br, fl, bl) angle = 0 rotation = '' running = True while running: screen.fill((0,0,0)) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.JOYBUTTONDOWN: #This will include all button actions # 0 = A
# Automobile Example # test2.py file from automobile import Automobile herbie = Automobile("VW Bug", "yellow") christine = Automobile("Plymouth Fury", "red") print(christine.color) herbie.color = "white" for i in range(0, 5): herbie.accelerate() christine.accelerate() print("herbie", herbie.velocity) print("christine", christine.velocity) for i in range(0, 3): herbie.brake() print(christine.velocity, herbie.velocity) print(herbie) print(christine)
self.velocity += 15 if self.velocity > 120.0: self.velocity = 120.0 def brake(self): self.velocity -= 20 if self.velocity < 0.0: self.velocity = 0.0 # Automobile Example # test1.py file from automobile import Automobile auto = Automobile("Ford Taurus", "red") print(str(auto)) # Next line has same effect as preceding line. # str method is automatically called when # an object printed. print(auto) print(auto.model, auto.color) auto.accelerate() auto.accelerate() auto.accelerate() print(auto.velocity) auto.brake() auto.brake() print(auto.velocity)
def test_ID(self): autoId = Automobile(123, 'sedan', 'merceedes', 'red', 1994, 2000) self.assertEqual(self.auto.vehicle_id, autoId)
def test_Model(self): model = Automobile(123, 'sedan', 'merceedes', 'red', 1994, 2000) self.assertEqual(self.auto.get_model(), 'sedan')