Skip to content

Algorithms&data structures 5 - #10

Open
SRytv wants to merge 13 commits into
masterfrom
Algorithms&Data_Structures_5
Open

Algorithms&data structures 5#10
SRytv wants to merge 13 commits into
masterfrom
Algorithms&Data_Structures_5

Conversation

@SRytv

@SRytv SRytv commented Oct 11, 2018

Copy link
Copy Markdown
Owner

Здравствуйте, Алексей! У меня к Вам просьба. В задаче 2, я не смог подобрать необходимой последовательности индексов в циклах в программах "mult_hex" и "sum_hex" для получения всех(!) символов из deque в порядке от последнего до самого первого (я непременно "терял" либо последний, либо 1-й), поэтому пришлось воспользоваться методом pop(). Подскажите, пожалуйста, как мне следовало бы организовать цикл, для получения всех символов, чтобы не пользоваться этим pop() и не портить сомножитель, (слагаемое) и обойтись без сохраняющего их копирования. С уважением, Сергей!

@Dzhoker1 Dzhoker1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оставил комментарии по коду

fact_name = input("введите название {: >2d}-го предприятия : ".format(i + 1))
for j in range(1, 5):
profit = int(input("Введите его прибыль за {: >2d}-й квартал : ".format(j)))
fact_income[fact_name] += profit

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отличное использование defaultdict

fact_income[fact_name] += profit
print('I', fact_income[fact_name])
fact_income[fact_name] /= 4
all_fact_profit_sum = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Общую прибыль можно было считать в процессе ввода данных и цикл ниже оказался бы не нужен.

import collections
import copy

hex_values = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Основной код перемешан с функциями. Так не принято писать. Сначала все функции, потом внешний код. Привыкайте к хорошему стилю.

#==================================================================================================================

def sum_hex(hex_1, hex_2):
hex_1c = copy.copy(hex_1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В моём решении будет точно такое же копирование )))

hex_result = collections.deque([])
hex_len = len(hex_1c)
carry = 0
for i in range(hex_len):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверное вам нужен был следующий цикл 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это же самое настоящее умножение в столбик. Супер.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants