Skip to content

Решение шестого практического задания#8

Open
SergeyZ06 wants to merge 2 commits intomainfrom
6th_hometask
Open

Решение шестого практического задания#8
SergeyZ06 wants to merge 2 commits intomainfrom
6th_hometask

Conversation

@SergeyZ06
Copy link
Copy Markdown
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!')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
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.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
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.

2 participants