-
Notifications
You must be signed in to change notification settings - Fork 0
ДЗ к 6 уроку #4
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?
ДЗ к 6 уроку #4
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from time import sleep | ||
|
|
||
|
|
||
| class TrafficLight: | ||
| __color = [('красный', 2), ('желтый', 2), ('зеленый', 3)] | ||
|
|
||
| def running(self): | ||
| for a, b in self.__color: | ||
| print(a) | ||
| sleep(b) | ||
|
|
||
|
|
||
| c = TrafficLight() | ||
| c.running() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Road: | ||
| def __init__(self, length, width): | ||
| self._length = length | ||
| self._width = width | ||
|
|
||
| def mass(self, thickness, mass_sm): | ||
| return self._length*self._width*thickness*mass_sm | ||
|
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. помни про форматирование |
||
|
|
||
|
|
||
| Road_1 = Road(20, 5000) | ||
| print(Road_1.mass(25, 5)) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| income = {'worker1': {'wage': 10000, 'bonus': 5000}, 'worker2': {'wage': 20000, 'bonus': 5000}} | ||
|
|
||
|
|
||
| class Worker: | ||
| def __init__(self, name, surname, position): | ||
| self.name = name | ||
| self.surname = surname | ||
| self.position = position | ||
| self._income = income[position] | ||
|
|
||
|
|
||
| class Position(Worker): | ||
| def get_full_name(self): | ||
| print(f'Имя: {self.name}\n' | ||
| f'Фамилия: {self.surname}') | ||
|
|
||
| def get_total_income(self): | ||
| print(f'Общий доход {self._income["wage"]+self._income["bonus"]}') | ||
|
|
||
|
|
||
| a = Position("Иван", "Иванов", 'worker1') | ||
|
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. тут тоже обзови переменную более информативно |
||
| a.get_full_name() | ||
| a.get_total_income() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| class Car: | ||
|
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. отлично! |
||
| def __init__(self, speed, color, name, is_police=False): | ||
| self.speed = speed | ||
| self.color = color | ||
| self.name = name | ||
| self.is_police = is_police | ||
|
|
||
| def go(self, speed=0): | ||
| self.speed += speed | ||
| if self.speed == 0: | ||
| self.speed = int(input('Введите скорость: ')) | ||
| print(f'Машина поехала со скоростью {self.speed}') | ||
|
|
||
| def stop(self): | ||
| print('Машина остановилась') | ||
| self.speed = 0 | ||
|
|
||
| def turn(self, direction): | ||
| print(f'Машина повернула в направлении {direction}') | ||
|
|
||
| def show_speed(self): | ||
| print(f'Текущая скорость {self.speed}') | ||
|
|
||
|
|
||
| class TownCar(Car): | ||
| def show_speed(self): | ||
| print(f'Текущая скорость {self.speed}') | ||
| if self.speed > 60: | ||
| print('Скорость превышена!') | ||
|
|
||
|
|
||
| class WorkCar(Car): | ||
| def show_speed(self): | ||
| print(f'Текущая скорость {self.speed}') | ||
| if self.speed > 40: | ||
| print('Скорость превышена!') | ||
|
|
||
|
|
||
| class SportCar(Car): | ||
| pass | ||
|
|
||
|
|
||
| class PoliceCar(Car): | ||
| is_police = True | ||
|
|
||
|
|
||
| TownCar1 = TownCar(61, 'black', 'Tree') | ||
| TownCar1.go(10) | ||
| TownCar1.show_speed() | ||
| print(TownCar1.is_police) | ||
| print(TownCar1.color) | ||
| TownCar1.stop() | ||
| TownCar1.go(30) | ||
| TownCar1.show_speed() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class Stationery: | ||
| def __init__(self, title): | ||
| self.title = title | ||
|
|
||
| def draw(self): | ||
| print('Запуск отрисовки') | ||
|
|
||
|
|
||
| class Pen(Stationery): | ||
| def draw(self): | ||
| print('Запуск отрисовки ручкой') | ||
|
|
||
|
|
||
| class Pencil(Stationery): | ||
| def draw(self): | ||
| print('Запуск отрисовки карандашом') | ||
|
|
||
|
|
||
| class Handle(Stationery): | ||
| def draw(self): | ||
| print('Запуск отрисовки маркером') | ||
|
|
||
|
|
||
| a = Stationery('Рисунок1') | ||
| a.draw() | ||
| b = Pen('Рисунок2') | ||
| b.draw() | ||
| c = Pencil('Рисунок3') | ||
| c.draw() | ||
| d = Handle('Рисунок4') | ||
| d.draw() |
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.
хорошо! давай улучшим немного и обзовём переменные как light_color и light_time