Guest User

Untitled

a guest
Jan 10th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. # Задача - 1
  2. # Опишите несколько классов TownCar, SportCar, WorkCar, PoliceCar
  3. # У каждого класса должны быть следующие аттрибуты:
  4. # speed, color, name, is_police - Булево значение.
  5. # А так же несколько методов: go, stop, turn(direction) - которые должны сообщать,
  6. # о том что машина поехала, остановилась, повернула(куда)
  7. class towncar:
  8. def __init__(self, name, speed, color, is_police):
  9. self.name = name
  10. self.speed = speed
  11. self.color = color
  12. self.is_police = is_police
  13. def go(self):
  14. print('машина поехала')
  15. def stop(self):
  16. print('машина поехала')
  17. def turn(self):
  18. print('машина поехала')
  19.  
  20. class sportcar:
  21. def __init__(self, name, speed, color, is_police):
  22. self.name = name
  23. self.speed = speed
  24. self.color = color
  25. self.is_police = is_police
  26. def go(self):
  27. print('машина поехала')
  28. def stop(self):
  29. print('машина поехала')
  30. def turn(self):
  31. print('машина поехала')
  32.  
  33. class workcar:
  34. def __init__(self, name, speed, color, is_police):
  35. self.name = name
  36. self.speed = speed
  37. self.color = color
  38. self.is_police = is_police
  39. def go(self):
  40. print('машина поехала')
  41. def stop(self):
  42. print('машина поехала')
  43. def turn(self):
  44. print('машина поехала')
  45.  
  46. class Policecar:
  47. def __init__(self, name, speed, color, is_police):
  48. self.name = name
  49. self.speed = speed
  50. self.color = color
  51. self.is_police = is_police
  52. def go(self):
  53. print('машина поехала')
  54. def stop(self):
  55. print('машина поехала')
  56. def turn(self):
  57. print('машина поехала')
  58.  
  59. # Задача - 2
  60. # Посмотрите на задачу-1 подумайте как выделить общие признаки классов
  61. # в родительский и остальные просто наследовать от него.
  62.  
  63. auto=towncar('ford',120,'red',0,)
  64. print(auto.name,auto.speed,auto.color,auto.is_police)
  65. auto.go
Advertisement
Add Comment
Please, Sign In to add comment