Advertisement
Guest User

Untitled

a guest
May 24th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 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. # Задача - 2 (СДЕЛАНО)
  8. # Посмотрите на задачу-1 подумайте как выделить общие признаки классов
  9. # в родительский и остальные просто наследовать от него.
  10. class TownCar:
  11.     def __init__(self, car):
  12.         self.speed = 60
  13.         self.color = 'white'
  14.         self.name = car
  15.         self._is_police = False
  16.  
  17.     def go(self):
  18.         print(f'the car is driving with {self.speed} m/p/h')
  19.  
  20.     def stop(self):
  21.         print('The car has been stopped')
  22.  
  23.     def turn_direction(self):
  24.         print('The car is turning left or right')
  25.  
  26. town_car = TownCar('toyota')
  27. print(town_car.color)
  28.  
  29. class SportCar(TownCar):
  30.     def __init__(self,car):
  31.         super(). __init__(car)
  32.         self.speed = 200
  33.         self.color = 'red'
  34.  
  35. sport_car = SportCar('lamborgini')
  36. print(sport_car.speed)
  37. print(sport_car._is_police)
  38.  
  39. class WorkCar(TownCar):
  40.     def __init__(self,car):
  41.         super(). __init__(car)
  42.         self.speed = 30
  43.         self.color = 'blue'
  44.  
  45. work_car = WorkCar('truck')
  46. print(work_car.speed)
  47. print(work_car.color)
  48. print(work_car.go)
  49.  
  50. class PoliceCar(TownCar):
  51.     def __init__(self,car):
  52.         super(). __init__(car)
  53.         self.speed = 90
  54.         self.color = 'black and white'
  55.         self._is_police = True
  56.  
  57. police_car = PoliceCar('crown_victoria')
  58. print(police_car.speed)
  59. print(police_car.color)
  60. print(police_car.go)
  61. print(police_car._is_police)
  62.  
  63. # Здесь так и не разобрался почему, например, print(police_car.go) возвращает закую-то фигню, а не то, что задумано.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement