Skip to content

Conversation

@SergeyZ06
Copy link
Owner

No description provided.

Comment on lines 64 to 73
def show_speed(self):
#
if self.speed <= self.__allowed_speed:
#
print(f'{self.name}s speed is {self.speed} kmph')
# иначе
else:
#
print(f'{self.name}s speed is {self.speed} kmph. '
f'Exceeded legal amount on {self.speed - self.__allowed_speed} kmph!')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У вас же эта функция уже есть в городской машине. Можете просто унаследоваться от нее и все будет работать аналогично (ведь допустимую скорость вы переопределяете и проверка в функции корректно все обработает)

Copy link
Owner Author

@SergeyZ06 SergeyZ06 Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделал наследование от Городской машины, но теперь и переменная допустимой скорости берётся от Городской машины, а не переопределяется в классе Рабочая машина.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А в чем проблема переопределить её в Рабочей?)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, так и делал сперва, но ничего не получилось
Дело оказалось в приватной переменной __allowed_speed, заменил её на защищённую _allowed_speed и всё заработало!
Спасибо за помощь

исправлена ошибка проверка скорости Рабочей машины. Тип переменной "Разрешённая скорость" изменён с приватной на защищённую. Теперь переменная корректно переопределяется в дочернем классе Рабочая машина.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants