-
Notifications
You must be signed in to change notification settings - Fork 0
Решение седьмого практического задания #9
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: main
Are you sure you want to change the base?
Conversation
- добавлено решение второго пункта задания
- добавлено решение третьего пункта задания
| new_matrix.append([]) | ||
| # для каждых элементов слагаемых матриц | ||
| for index_x, value_x in enumerate(value_y): | ||
| # добавить в список новой матрицы вычисленный элемент | ||
| new_matrix[index_y].append(self.matrix_list[index_y][index_x] + value_x) |
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.
Все верно здесь, просто чтоб меньше путаться можно так сделать:
new_row = []
# для каждых элементов слагаемых матриц
for index_x, value_x in enumerate(value_y):
# добавить в список новой матрицы вычисленный элемент
new_row.append(self.matrix_list[index_y][index_x] + value_x)
new_matrix.append(new_row)
чтоб лишний индекс не отслеживать и не делать лишние движения по нему.
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.
Наверно да, так будет выглядеть менее грамозко
Но мне почему-то проще именно в двумерном пространстве работать
| # Попытка обработать исключение при обращении к Клетке, в случае вычитания с отрицательным результатом | ||
| # Не получилось, так как в переменную записывается не ссылка на новый объект без параметра, а ссылка на None | ||
| # Поэтому обрабатывать исключение пришлось в коде программы | ||
| def __getattr__(self, item): | ||
| if item == self.number_of_cells: | ||
| try: | ||
| return self.number_of_cells | ||
| except AttributeError: | ||
| return f'Current cell do not have attribute "number_of_cells".' \ |
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.
Хорошо что решил учесть. Но проще, думаю, будет в самой функции деления или при инициализации клетки проверить через if значение.
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.
Ага, так и сделал проверку в методе вычитания, так тут логически не получилось
Если в результате вычитания получается отрицательное число, но в переменную новой клетки записывается не ссылка на новый объект, а на ссылка на None
Поэтому этот метод не работает, так как новая клетка не является объектом класса клетка
No description provided.