proffreda

car.py

Oct 23rd, 2016
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class Car(object):
  2. num_wheels = 4
  3. gas = 30
  4. headlights = 2
  5. size = 'Tiny'
  6.  
  7. def __init__(self, make, model):
  8. self.make = make
  9. self.model = model
  10. self.color = 'No color yet. You need to paint me.'
  11. self.wheels = Car.num_wheels
  12. self.gas = Car.gas
  13.  
  14. def paint(self, color):
  15. self.color = color
  16. return self.make + ' ' + self.model + ' is now ' + color
  17.  
  18. def drive(self):
  19. if self.wheels < Car.num_wheels or self.gas <= 0:
  20. return self.make + ' ' + self.model + ' cannot drive!'
  21. self.gas -= 10
  22. return self.make + ' ' + self.model + ' goes vroom!'
  23.  
  24. def pop_tire(self):
  25. if self.wheels > 0:
  26. self.wheels -= 1
  27.  
  28. def fill_gas(self):
  29. self.gas += 30
  30. print('Your car is full.')
  31.  
  32.  
  33. class MonsterTruck(Car):
  34. size = 'Monster'
  35.  
  36. def rev(self):
  37. print('Vroom! This Monster Truck is huge!')
  38.  
  39. def drive(self):
  40. self.rev()
  41. return Car.drive(self)
Advertisement
Add Comment
Please, Sign In to add comment