# 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)
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) auto.brake() print(auto.velocity)