-
Notifications
You must be signed in to change notification settings - Fork 0
ДЗ к 7 уроку #5
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
getblad
wants to merge
1
commit into
master
Choose a base branch
from
lesson7
base: master
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
ДЗ к 7 уроку #5
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,21 @@ | ||
| class Matrix: | ||
| def __init__(self, matrix_list): | ||
| self.matrix = matrix_list | ||
|
|
||
| def __str__(self): | ||
| for list in self.matrix: | ||
| for number in list: | ||
| print(number, end=' ') | ||
| print() | ||
| return '' | ||
|
|
||
| def __add__(self, other): | ||
| return Matrix([[i+n for i, n in zip(a, b)] for a, b in zip(self.matrix, other.matrix)]) | ||
|
|
||
|
|
||
| matrix = [[1, 2, 3, 5], [1, 2, 3, 4], [1, 2, 2, 7]] | ||
| matrix2 = [[1, 2, 3, 5], [1, 2, 3, 4], [1, 2, 2, 7]] | ||
| ma = Matrix(matrix) | ||
| ma2 = Matrix(matrix2) | ||
| c = ma + ma2 | ||
|
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. лучше обзывать переменные поинформативнее |
||
| print(c) | ||
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,29 @@ | ||
| class Clothes: | ||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
|
|
||
| class Costume(Clothes): | ||
| def __init__(self, name, height): | ||
| super().__init__(name) | ||
| self.height = height | ||
|
|
||
| @property | ||
| def consumption(self): | ||
| return f'Расход ткани на {self.name} составит {2 * self.height + 3}' | ||
|
|
||
|
|
||
| class Coat(Clothes): | ||
| def __init__(self, name, size): | ||
| super().__init__(name) | ||
| self.size = size | ||
|
|
||
| @property | ||
| def consumption(self): | ||
| return f'Расход ткани на {self.name} составит {self.size / 6.5 + 0.5:.2f}' | ||
|
|
||
|
|
||
| My_costume = Costume('ASD', 29) | ||
| My_coat = Coat('Wary', 30) | ||
| print(My_costume.consumption) | ||
| print(My_coat.consumption) |
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,54 @@ | ||
| class Cell: | ||
|
|
||
| def __init__(self, quantity): | ||
| self.quantity = quantity | ||
|
|
||
| def __add__(self, other): | ||
| return Cell(self.quantity + other.quantity) | ||
|
|
||
| def __sub__(self, other): | ||
| sub = self.quantity - other.quantity | ||
| if sub > 0: | ||
| return Cell(sub) | ||
| else: | ||
| print(f'Из клетки {self.get_name()} невозможно вычесть {other.get_name()}', end='') | ||
|
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. да тут прямо можно влупить raise ValueError, чтобы неповадно было |
||
| return '' | ||
|
|
||
| def __mul__(self, other): | ||
| return Cell(self.quantity * other.quantity) | ||
|
|
||
| def __truediv__(self, other): | ||
| return Cell(self.quantity // other.quantity) | ||
|
|
||
| def __str__(self): | ||
| return str(self.quantity) | ||
|
|
||
| def get_name(self): | ||
| for k, v in globals().items(): | ||
| if v is self: | ||
| return k | ||
|
|
||
| def make_order(self, row): | ||
| a = '' | ||
| if row > self.quantity: | ||
| return f'{"*" * self.quantity}' | ||
| n = 0 | ||
| for i in range(self.quantity//row + 1): | ||
| if self.quantity - n < row: | ||
| a = ''.join([a, f'{"*" * (self.quantity - n)}\n']) | ||
| return a | ||
| a = ''.join([a, f'{"*" * row}\n']) | ||
| n += row | ||
| return a | ||
|
|
||
|
|
||
| x = Cell(3) | ||
| y = Cell(11) | ||
|
|
||
| print(y - x) | ||
| print(x - y) | ||
| print(x*y) | ||
| print(x+y) | ||
| print(x/y) | ||
| print(y/x) | ||
| print(y.make_order(2)) | ||
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.
это самое короткое и элегантное решение, что я видел)