Algorithms&data structures 5 - #10
Open
SRytv wants to merge 13 commits into
Open
Conversation
…, в основном только наметки.
Dzhoker1
reviewed
Oct 11, 2018
| fact_name = input("введите название {: >2d}-го предприятия : ".format(i + 1)) | ||
| for j in range(1, 5): | ||
| profit = int(input("Введите его прибыль за {: >2d}-й квартал : ".format(j))) | ||
| fact_income[fact_name] += profit |
| fact_income[fact_name] += profit | ||
| print('I', fact_income[fact_name]) | ||
| fact_income[fact_name] /= 4 | ||
| all_fact_profit_sum = 0 |
There was a problem hiding this comment.
Общую прибыль можно было считать в процессе ввода данных и цикл ниже оказался бы не нужен.
| import collections | ||
| import copy | ||
|
|
||
| hex_values = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, |
There was a problem hiding this comment.
Основной код перемешан с функциями. Так не принято писать. Сначала все функции, потом внешний код. Привыкайте к хорошему стилю.
| #================================================================================================================== | ||
|
|
||
| def sum_hex(hex_1, hex_2): | ||
| hex_1c = copy.copy(hex_1) |
There was a problem hiding this comment.
В моём решении будет точно такое же копирование )))
| hex_result = collections.deque([]) | ||
| hex_len = len(hex_1c) | ||
| carry = 0 | ||
| for i in range(hex_len): |
There was a problem hiding this comment.
Наверное вам нужен был следующий цикл for i in range(hex_len - 1, -1, -1) - от последнего элемента включительно до -1 элемента исключительно с шагом -1
| hex_2 = collections.deque(list((hex_2_input).lower())) | ||
|
|
||
| #================================================================================================================== | ||
| def mult_hex(hex_1, hex_2): |
There was a problem hiding this comment.
Это же самое настоящее умножение в столбик. Супер.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Здравствуйте, Алексей! У меня к Вам просьба. В задаче 2, я не смог подобрать необходимой последовательности индексов в циклах в программах "mult_hex" и "sum_hex" для получения всех(!) символов из deque в порядке от последнего до самого первого (я непременно "терял" либо последний, либо 1-й), поэтому пришлось воспользоваться методом pop(). Подскажите, пожалуйста, как мне следовало бы организовать цикл, для получения всех символов, чтобы не пользоваться этим pop() и не портить сомножитель, (слагаемое) и обойтись без сохраняющего их копирования. С уважением, Сергей!