-
Notifications
You must be signed in to change notification settings - Fork 325
Lesson 6 #1785
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?
Lesson 6 #1785
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,19 @@ | |
|
|
||
| Например: 20м*5000м*25кг*0.05м = 125000 кг = 125 т | ||
| """ | ||
|
|
||
|
|
||
| class Road: | ||
| weight = 25 | ||
| thickness = 5 | ||
|
|
||
| def __init__(self, length, width): | ||
| self._length = length | ||
| self._width = width | ||
|
|
||
| def asphalt_weight(self): | ||
| return self.weight * self.thickness * self._length * self._width / 1000 | ||
|
|
||
|
|
||
| my_road = Road(5000, 20) | ||
| print(f'Масса асфальта = {my_road.asphalt_weight()} тонн') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,27 @@ | |
| П.С. попытайтесь добить вывода информации о сотруднике также через перегрузку __str__ | ||
| __str__(self) - вызывается функциями str, print и format. Возвращает строковое представление объекта. | ||
| """ | ||
|
|
||
|
|
||
| class Worker: | ||
| def __init__(self, name, surname_f, surname, position, wage, bonus): | ||
| self.name = name | ||
| self.surname_f = surname_f | ||
| self.surname = surname | ||
| self.position = position | ||
| self._income = {"wage": wage, "bonus": bonus} #_private | ||
|
|
||
| class Position(Worker): | ||
| def __init__(self, name, surname_f, surname, position, wage, bonus): | ||
| super().__init__(name, surname_f, surname, position, wage, bonus) | ||
|
|
||
| def get_full_name(self): | ||
| return self.name + ' ' + self.surname_f + ' ' + self.surname | ||
|
|
||
| def get_total_income(self): | ||
| return f'{sum(self._income.values())}' | ||
|
|
||
| a = Position('Путин', 'Александр', 'Николаевич', 'Президент Российской Империи', 100000, 500) | ||
| print(f'ФИО : {a.get_full_name()}') | ||
| print(f'Должность : {a.position}') | ||
| print(f'Доход : {a.get_total_income()}') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,102 @@ | |
| Выполните доступ к атрибутам, выведите результат. | ||
| Выполните вызов методов и также покажите результат. | ||
| """ | ||
|
|
||
|
|
||
| class Car: | ||
|
|
||
| def __init__(self, max_speed, color, name, is_police): | ||
| self.max_speed = max_speed | ||
| self.color = color | ||
| self.name = name | ||
| self.is_police = is_police | ||
|
|
||
| def go(self): | ||
| print(f'Начало движения {self.name}') | ||
|
|
||
| def stop(self): | ||
| print(f'Остановка {self.name} ') | ||
|
|
||
| def turn(self, direction): | ||
| print(f'{self.name} поворачивает {direction}') | ||
|
|
||
| def show_speed(self, speed): | ||
| print(f'Скорость движения автомобиля - {self.speed}') | ||
| if self.speed > self.max_speed and not self.is_police: | ||
| print(f'Автомобиль {self.name} превысил скорость') | ||
|
|
||
|
|
||
| class TownCar(Car): | ||
| def __init__(self, speed, color, name, is_police): | ||
| super().__init__(speed, color, name, is_police) | ||
|
|
||
| def show_speed(self, speed): | ||
| self.speed = speed | ||
| super().show_speed(self.speed) | ||
|
|
||
|
|
||
| class SportCar(Car): | ||
| def __init__(self, speed, color, name, is_police): | ||
| super().__init__(speed, color, name, is_police) | ||
|
|
||
| def show_speed(self, speed): | ||
| self.speed = speed | ||
| super().show_speed(self.speed) | ||
|
|
||
| class WorkCar(Car): | ||
| def __init__(self, speed, color, name, is_police): | ||
| super().__init__(speed, color, name, is_police) | ||
|
|
||
| def show_speed(self, speed): | ||
| self.speed = speed | ||
| super().show_speed(self.speed) | ||
|
|
||
|
|
||
| class PoliceCar(Car): | ||
| def __init__(self, speed, color, name, is_police): | ||
| super().__init__(speed, color, name, is_police) | ||
|
|
||
| def show_speed(self, speed): | ||
| self.speed = speed | ||
| super().show_speed(self.speed) | ||
|
|
||
|
|
||
| emobil = TownCar(60, 'Желтый', 'Ёмобиль', False) | ||
| emobil.go() | ||
| emobil.show_speed(50) | ||
| emobil.turn('налево') | ||
| emobil.go() | ||
| emobil.show_speed(70) | ||
| emobil.stop() | ||
| print() | ||
|
|
||
| toyota = WorkCar(80, 'Серый', 'Toyota', False) | ||
| toyota.go() | ||
| toyota.show_speed(60) | ||
| toyota.turn('направо') | ||
| toyota.go() | ||
| toyota.turn('направо') | ||
| toyota.show_speed(90) | ||
| toyota.stop() | ||
| toyota.go() | ||
| toyota.show_speed(50) | ||
| toyota.turn('налево') | ||
| print() | ||
|
|
||
| lada_sport = SportCar(90, 'Зелёный', 'Lada Kalina Sport', False) | ||
| lada_sport.go() | ||
| # subaru.show_speed(110) | ||
| lada_sport.turn('направо') | ||
| lada_sport.turn('направо') | ||
| lada_sport.go() | ||
| lada_sport.show_speed(180) | ||
| lada_sport.show_speed(210) | ||
| lada_sport.show_speed(230) | ||
| print() | ||
|
|
||
| lada_vesta = PoliceCar(110, 'Белый', 'Lada Vesta', True) | ||
| lada_vesta.go() | ||
| lada_vesta.show_speed(110) | ||
| lada_vesta.show_speed(150) | ||
| lada_vesta.stop() | ||
| print() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,40 @@ | |
| Для каждого из классов метод должен выводить уникальное сообщение. | ||
| Создать экземпляры классов и проверить, что выведет описанный метод для каждого экземпляра. | ||
| """ | ||
|
|
||
|
|
||
| class Stationery: | ||
|
|
||
| def __init__(self, title): | ||
| self.title = title | ||
|
|
||
| def draw(self): | ||
| return f'Запуск отрисовки' | ||
|
|
||
|
|
||
| class Pen(Stationery): | ||
|
|
||
| def draw(self): | ||
| return f'{self.title} - Запуск отрисовки' | ||
|
|
||
|
|
||
| class Pencil(Stationery): | ||
|
|
||
| def draw(self): | ||
| return f'{self.title} - Запуск отрисовки' | ||
|
|
||
|
|
||
| class Handle(Stationery): | ||
|
|
||
| def draw(self): | ||
| return f'{self.title} - Запуск отрисовки' | ||
|
|
||
|
|
||
| pen = Pen('Ручка') | ||
| print(pen.draw()) | ||
|
|
||
| pencil = Pencil('Карандаш') | ||
| print(pencil.draw()) | ||
|
|
||
| handle = Handle('Маркер') | ||
| print(handle.draw()) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
||
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.
выполнено