-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 6 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
|
|
||
| class TrafficLight: | ||
| __color = [('красный', 7), ('желтый', 2), ('зеленый', 6)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а ещё можно юзать словарть)
| for element in self.__color: | ||
| if element[0] not in colors: | ||
| print('Некорректные цвета') | ||
| elif self.__color[0][0] != colors[0] or self.__color[1][0] != colors[1] or self.__color[2][0] != colors[2]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно запихнуть логику по временным пределам горения светофора в словарь) Это будет удобнее, загляни в разбор!)
А ещё это позволит избавиться от копипасты кода и if-ов.
| self._length = length | ||
| self._width = width | ||
|
|
||
| def mass_calculation(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай тут добавим параметр толщины и будем прокидывать его в функцию, как просят в условии
|
|
||
| def __init__(self, name, surname, position, income): | ||
| super().__init__(name, surname, position, income) | ||
| self._full_income_value = self._income.get('wage') + self._income.get('bonus') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это лучше вынести в проперти или в отдельный метод
|
|
||
| class TownCar(Car): | ||
| def __init__(self, name, speed, color, is_police): | ||
| super().__init__(name, speed, color, is_police) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Смотри, у тебя тут и в аналогичных случаях поведение родительского метода никак не переопределяется.
Ты не дописываешь новых полей и не изменяешь значения старых.
То есть поведение никак не меняется, поэтому смысла переопределять этот метод нет.
| super().__init__(name, speed, color, is_police) | ||
|
|
||
| def show_speed(self): | ||
| if self.speed <= 60: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ограничение скорости тут и в остальных классах можно убрать в поле самого класса)
|
|
||
| if __name__ == '__main__': | ||
| t = TownCar(speed=48, color='green', name='УАЗ-3303', is_police=False) | ||
| s = SportCar(speed=180, color='red', name='Ferrari 488', is_police=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пора учиться писать тесты) - https://www.youtube.com/watch?v=1HtEPEn4-LY&t=306s&ab_channel=Luchanos
|
|
||
| class Pen(Stationery): | ||
| def __init__(self, title): | ||
| super().__init__(title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут то же что и выше - нет необходимости переопределять
No description provided.