-
Notifications
You must be signed in to change notification settings - Fork 0
Added hometask 6 #7
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
Open
dkyopwa
wants to merge
1
commit into
main
Choose a base branch
from
hometask6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env python | ||
| # nevl 2021 | ||
|
|
||
| import time | ||
|
|
||
| class TrafficLight: | ||
| __color = 'red' | ||
|
|
||
| def running(self): | ||
| print('TrafficLight running') | ||
| for _ in range(10): | ||
| if self.__color == 'red': | ||
| for i in range(7, 0, -1): | ||
| print(f'\rred (7): {i}', end='') | ||
| time.sleep(1) | ||
| self.__color = 'yellow' | ||
| elif self.__color == 'yellow': | ||
| for i in range(2, 0, -1): | ||
| print(f'\ryellow (2): {i}', end='') | ||
| time.sleep(1) | ||
| self.__color = 'green' | ||
| elif self.__color == 'green': | ||
| for i in range(10, 0, -1): | ||
| print(f'\rgreen (10): {i}', end='') | ||
| time.sleep(1) | ||
| self.__color = 'red' | ||
| print('TrafficLight stop') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| tf = TrafficLight() | ||
| tf.running() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/env python | ||
| # nevl 2021 | ||
|
|
||
| class Road: | ||
| __length = 0.0 | ||
| __width = 0.0 | ||
|
|
||
| def __init__(self, length, width): | ||
| self.__length = length | ||
| self.__width = width | ||
|
|
||
| def calc(self, depth=1): | ||
| return self.__length * self.__width * 25 * depth / 1000.0 | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| road = Road(5000, 20) | ||
| print(road.calc(5)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env python | ||
| # nevl 2021 | ||
|
|
||
| class Worker: | ||
| name = '' | ||
| surname = '' | ||
| position = '' | ||
| __income = {"wage": 0, "bonus": 0} | ||
|
|
||
| def __init__(self, name, surname, position, wage, bonus): | ||
| self.name = name | ||
| self.surname = surname | ||
| self.position = position | ||
| self.__income['wage'] = wage | ||
| self.__income['bonus'] = bonus | ||
|
|
||
| def get_income(self): | ||
| return self.__income | ||
|
|
||
|
|
||
| class Position(Worker): | ||
| def get_full_name(self): | ||
| return f'{self.name} {self.surname} {self.position}' | ||
|
|
||
| def get_total_income(self): | ||
| income = self.get_income() | ||
| return income['wage'] + income['bonus'] | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| pos = Position('John', 'Doe', 'plumber', 20000, 500) | ||
| print(pos.get_full_name()) | ||
| print(pos.get_total_income()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/usr/bin/env python | ||
| # nevl 2021 | ||
|
|
||
| import random | ||
|
|
||
| class Car: | ||
| speed = 0 | ||
| color = '' | ||
| name = '' | ||
| is_police = False | ||
|
|
||
| def __init__(self, color, name, is_police=False): | ||
| self.color = color | ||
| self.name = name | ||
| self.is_police = is_police | ||
|
|
||
| def go(self): | ||
| self.speed = random.randint(1, 100) | ||
| print(f'Car {self.name} ({self.color}) is going') | ||
|
|
||
| def stop(self): | ||
| self.speed = 0 | ||
| print(f'Car {self.name} ({self.color}) is staying') | ||
|
|
||
| def turn(self, direction): | ||
| if self.speed: | ||
| print(f'Car {self.name} ({self.color}) turned to the {direction}') | ||
| else: | ||
| print(f'Car {self.name} ({self.color}) is staying') | ||
|
|
||
| def show_speed(self): | ||
| if self.speed <= 0: | ||
| print(f'Car {self.name} ({self.color}) is staying. Speed 0 km/h') | ||
| print(f'Speed car {self.name} ({self.color}) is {self.speed} km/h') | ||
|
|
||
|
|
||
| class TownCar(Car): | ||
| def show_speed(self): | ||
| super().show_speed() | ||
| if self.speed > 60: | ||
| print('Over speed ') | ||
|
|
||
|
|
||
| class SportCar(Car): | ||
| pass | ||
|
|
||
|
|
||
| class WorkCar(Car): | ||
| def show_speed(self): | ||
| super().show_speed() | ||
| if self.speed > 40: | ||
| print('Over speed ') | ||
|
|
||
|
|
||
| class PoliceCar(Car): | ||
| def __init__(self, color, name, is_police=True): | ||
| super().__init__(color, name, is_police) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| tc = TownCar('red', 'Mazda') | ||
| tc.go() | ||
| tc.show_speed() | ||
| tc.turn('right') | ||
| tc.stop() | ||
| tc.show_speed() | ||
| print('-' * 30) | ||
|
|
||
| sc = SportCar('blue', 'Nissan GTR') | ||
| sc.go() | ||
| sc.show_speed() | ||
| sc.turn('left') | ||
| sc.stop() | ||
| sc.show_speed() | ||
| print('-' * 30) | ||
|
|
||
| wc = WorkCar('grey', 'MAZ') | ||
| wc.go() | ||
| wc.show_speed() | ||
| wc.turn('left') | ||
| wc.stop() | ||
| wc.show_speed() | ||
| print('-' * 30) | ||
|
|
||
|
|
||
| pc = PoliceCar('white', 'Mercedes') | ||
| pc.go() | ||
| pc.show_speed() | ||
| pc.turn('left') | ||
| pc.stop() | ||
| pc.show_speed() | ||
| print('-' * 30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env python | ||
| # nevl 2021 | ||
|
|
||
| class Stationery: | ||
| title = '' | ||
|
|
||
| def __init__(self, title): | ||
| self.title = title | ||
|
|
||
| def draw(self): | ||
| print('Drawing start') | ||
|
|
||
|
|
||
| class Pen(Stationery): | ||
| def __init__(self, title='Pen'): | ||
| super().__init__(title) | ||
|
|
||
| def draw(self): | ||
| print(f'Drawing super puper pen: {self.title}') | ||
|
|
||
|
|
||
| class Pencil(Stationery): | ||
| def __init__(self, title='Pencil'): | ||
| super().__init__(title) | ||
|
|
||
| def draw(self): | ||
| print(f'Pencil is a very important thing: {self.title}') | ||
|
|
||
|
|
||
| class Handle(Stationery): | ||
| def __init__(self, title='Handle'): | ||
| super().__init__(title) | ||
|
|
||
| def draw(self): | ||
| print(f'Handle is permanent marker: {self.title}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| pen = Pen() | ||
| pen.draw() | ||
|
|
||
| pencil = Pencil() | ||
| pencil.draw() | ||
|
|
||
| handle = Handle() | ||
| handle.draw() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
массу и толщину нужно было передавать как параметры