-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored gkitg/edu_tmp #1
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| even += 1 | ||
| else: | ||
| odd += 1 | ||
| num = num // 10 | ||
| num //= 10 | ||
| print(f"четных - {even}, нечетных - {odd}") | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| result = 0 | ||
| while num > 0: | ||
| result = result * 10 + num % 10 | ||
| num = num // 10 | ||
| num //= 10 | ||
|
Author
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. Lines
|
||
| print(result) | ||
|
|
||
| # вариант 2 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,7 @@ | |
|
|
||
| def sum_natural(n): | ||
| assert n < 999, 'Слишком большое число' | ||
| if n == 1: | ||
| return n | ||
| sum_n = n + sum_natural(n - 1) | ||
| return sum_n | ||
| return n if n == 1 else n + sum_natural(n - 1) | ||
|
Author
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. Function
|
||
|
|
||
|
|
||
| n = int(input('Введите любое натуральное число: ')) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,7 @@ | |
|
|
||
|
|
||
| def sum_digits(number): | ||
| if number < 10: | ||
| return number | ||
| return number % 10 + sum_digits(number // 10) | ||
| return number if number < 10 else number % 10 + sum_digits(number // 10) | ||
|
Author
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. Function
|
||
|
|
||
|
|
||
| num = int(input('Введите натуральное число. Ноль - выйти ')) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,7 @@ | |
| END_DIV = 9 | ||
| # вариант 1 | ||
| for i in range(START_DIV, END_DIV + 1): | ||
| frequency = 0 | ||
| for j in range(START_NUM, END_NUM + 1): | ||
| if j % i == 0: | ||
| frequency += 1 | ||
| frequency = sum(1 for j in range(START_NUM, END_NUM + 1) if j % i == 0) | ||
|
Author
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. Lines
|
||
| print(f'Числу {i} кратно {frequency} чисел') | ||
|
|
||
| # вариант 2 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,7 @@ | |
| array = [random.randint(MIN_ITEM, MAX_ITEM) for _ in range(SIZE)] | ||
| print(array) | ||
|
|
||
| result = [] | ||
| for i in range(len(array)): | ||
| if array[i] % 2 == 0: | ||
| result.append(i) | ||
| result = [i for i in range(len(array)) if array[i] % 2 == 0] | ||
|
Author
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. Lines
|
||
| print(f'Индексы чётных элементов: {result}') | ||
|
|
||
| result_new = [i for i in range(len(array)) if array[i] % 2 == 0] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,7 @@ | |
| num = array[0] | ||
| frequency = 1 | ||
| for i in range(len(array)): | ||
| spam = 1 | ||
| for j in range(i + 1, len(array)): | ||
| if array[i] == array[j]: | ||
| spam += 1 | ||
| spam = 1 + sum(1 for j in range(i + 1, len(array)) if array[i] == array[j]) | ||
|
Author
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. Lines
|
||
| if spam > frequency: | ||
| frequency = spam | ||
| num = array[i] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,16 +9,12 @@ | |
| array = [random.randint(MIN_ITEM, MAX_ITEM) for _ in range(SIZE)] | ||
| print(array) | ||
|
|
||
| # вариант 1 | ||
| i = 0 | ||
| index = -100500 | ||
| while i < len(array): # или for i in range(len(array)): | ||
| for i in range(len(array)): # или for i in range(len(array)): | ||
| if array[i] < 0 and index == -100500: | ||
| index = i | ||
| elif 0 > array[i] > array[index]: | ||
| index = i | ||
| i += 1 | ||
|
|
||
|
Comment on lines
-12
to
-21
Author
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. Lines
This removes the following comments ( why? ): |
||
| if index != -100500: | ||
| print(f'Максимальное отрицательное число {array[index]} ' | ||
| f'находится в ячейке {index}') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,5 @@ | |
| print(f'Левая граница: {array[idx_min]}\n' | ||
| f'Правая граница: {array[idx_max]}') | ||
|
|
||
| summ = 0 | ||
| for i in range(idx_min + 1, idx_max): | ||
| summ += array[i] | ||
| summ = sum(array[i] for i in range(idx_min + 1, idx_max)) | ||
|
Author
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. Lines
|
||
| print(f'Сумма = {summ}') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,9 @@ | |
| for j in range(len(matrix[0])): | ||
| min_ = matrix[0][j] | ||
|
|
||
| for i in range(len(matrix)): | ||
| if matrix[i][j] < min_: | ||
| min_ = matrix[i][j] | ||
| for item in matrix: | ||
| if item[j] < min_: | ||
| min_ = item[j] | ||
|
Comment on lines
-19
to
+21
Author
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. Lines
|
||
|
|
||
| if max_ is None or max_ < min_: | ||
| max_ = min_ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,35 +2,31 @@ | |
|
|
||
|
|
||
| n = int(input("Введите количество предприятий для расчета прибыли: ")) | ||
| d = dict() | ||
| a = 1 | ||
| for i in range(n): | ||
| d = {} | ||
| for a, _ in enumerate(range(n), start=1): | ||
| name = input("Введите название предприятия: ") | ||
| pr = input("через пробел введите прибыль данного предприятия\nза каждый квартал(Всего 4 квартала): ") | ||
| profit = pr.split(" ") | ||
| d[name] = profit | ||
| a += 1 | ||
|
Comment on lines
-5
to
-12
Author
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. Lines
|
||
| print() | ||
|
|
||
| fab = collections.Counter(d) | ||
|
|
||
| sc = [] | ||
| b = 0 | ||
| t = 0 | ||
| for i in fab: | ||
| summ = 0 | ||
| for j in fab[i]: | ||
| summ += int(j) | ||
| for i, value in fab.items(): | ||
| summ = sum(int(j) for j in value) | ||
| fab[i] = summ | ||
| t += summ | ||
| b += 1 | ||
| sec = t / b | ||
|
|
||
| print("Средняя годовая прибыль всех предприятий: " + str(sec)) | ||
| print(f"Средняя годовая прибыль всех предприятий: {str(sec)}") | ||
| bigger = [] | ||
| smaller = [] | ||
| for i in fab: | ||
| if int(fab[i]) >= sec: | ||
| for i, value_ in fab.items(): | ||
| if int(value_) >= sec: | ||
| bigger.append(i) | ||
| else: | ||
| smaller.append(i) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| org_lst.append(new_org) | ||
| print("-" * 5) | ||
|
|
||
| avg = sum([i.get('q_sum', 0.0) for i in org_lst]) / n | ||
| avg = sum(i.get('q_sum', 0.0) for i in org_lst) / n | ||
|
Author
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. Lines
|
||
| print(f"Предприятия с общей прибылью выше среднего (среднее = {avg:.2f}):", | ||
| ", ".join([f"{i.get('name')} ({i.get('q_sum')})" for i in org_lst if i.get('q_sum', 0.0) > avg])) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| companies = namedtuple("Company", " name period_1 period_2 period_3 period_4") | ||
| profit_aver = {} | ||
|
|
||
| for i in range(n): | ||
| for _ in range(n): | ||
|
Author
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. Lines
|
||
| company = companies(name=input("Введите название предприятия: "), | ||
| period_1=int(input("Введите прибыль за первый квартал: ")), | ||
| period_2=int(input("Введите прибыль за второй квартал: ")), | ||
|
|
@@ -13,9 +13,7 @@ | |
|
|
||
| profit_aver[company.name] = (company.period_1 + company.period_2 + company.period_3 + company.period_4) / 4 | ||
|
|
||
| total_aver = 0 | ||
| for value in profit_aver.values(): | ||
| total_aver += value | ||
| total_aver = sum(profit_aver.values()) | ||
| total_aver = total_aver / n | ||
|
|
||
| for key, value in profit_aver.items(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,10 @@ | |
| nums = collections.defaultdict(list) | ||
| for d in range(2): | ||
| n = input("Введите %d-е натуральное шестнадцатиричное число: " % (d+1)) | ||
| nums["%s-%s" % (d+1, n)] = list(n) | ||
| nums[f"{d + 1}-{n}"] = list(n) | ||
| print(nums) | ||
|
|
||
| sum = sum([int(''.join(i), 16) for i in nums.values()]) | ||
| sum = sum(int(''.join(i), 16) for i in nums.values()) | ||
|
Comment on lines
-18
to
+21
Author
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. Lines
|
||
| print("Сумма: ", list('%X' % sum)) | ||
|
|
||
| mult = functools.reduce(lambda a, b: a * b, [int(''.join(i), 16) for i in nums.values()]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,16 +13,16 @@ | |
|
|
||
|
|
||
| def hex_sum(x, y): | ||
| x = "".join([i for i in x]) | ||
| y = "".join([i for i in y]) | ||
| x = "".join(list(x)) | ||
| y = "".join(list(y)) | ||
|
Comment on lines
-16
to
+17
Author
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. Function
|
||
| s = hex((int(float.fromhex(x) + float.fromhex(y)))) | ||
| s = deque(s[2::].upper()) | ||
| print("Сумма:", s) | ||
|
|
||
|
|
||
| def hex_mul(x, y): | ||
| x = "".join([i for i in x]) | ||
| y = "".join([i for i in y]) | ||
| x = "".join(list(x)) | ||
| y = "".join(list(y)) | ||
|
Comment on lines
-24
to
+25
Author
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. Function
|
||
| s = hex((int(float.fromhex(x) * float.fromhex(y)))) | ||
| s = deque(s[2::].upper()) | ||
| print("Произведение:", s) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,14 +26,13 @@ def to_dec(self, x): | |
| def to_hex(self, x): | ||
| if x < 16: | ||
| return [str(x)] | ||
| else: | ||
| r = deque() | ||
| while x > 15: | ||
| d = x % 16 | ||
| r.appendleft(str(d) if d < 10 else self.hex_letters._fields[d-10]) | ||
| x = x // 16 | ||
| r.appendleft(str(x) if x < 10 else self.hex_letters._fields[x-10]) | ||
| return list(r) | ||
| r = deque() | ||
| while x > 15: | ||
| d = x % 16 | ||
| r.appendleft(str(d) if d < 10 else self.hex_letters._fields[d-10]) | ||
| x = x // 16 | ||
| r.appendleft(str(x) if x < 10 else self.hex_letters._fields[x-10]) | ||
| return list(r) | ||
|
Comment on lines
-29
to
+35
Author
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. Function
|
||
|
|
||
|
|
||
| a = input("Введите перове число в шестнадцатиричном формате: ").upper() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ def hex_to_decimal(num): | |
| for key, value in enumerate(HEX_NUMS): | ||
| hex_number[value] = key | ||
|
|
||
| return sum([hex_number[j] * (16 ** i) for i, j in enumerate(num)]) | ||
| return sum(hex_number[j] * (16 ** i) for i, j in enumerate(num)) | ||
|
Author
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. Function
|
||
|
|
||
|
|
||
| def decimal_to_hex(num): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,11 @@ def prime(num): | |
| 664579: 10 ** 7, | ||
| 5761455: 10 ** 8, | ||
| } | ||
| for key in pi_func.keys(): | ||
| for key, size in pi_func.items(): | ||
| if num <= key: | ||
| size = pi_func[key] | ||
| break | ||
|
|
||
| array = [i for i in range(size)] | ||
| array = list(range(size)) | ||
|
Comment on lines
-21
to
+25
Author
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. Function
|
||
|
|
||
| array[1] = 0 | ||
| for i in range(2, size): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,9 @@ | |
| all_comp = [] | ||
| Comp = namedtuple('Comp', 'name, p1, p2, p3, p4, total') | ||
| num = int(input('num = ')) | ||
| for i in range(num): | ||
| for _ in range(num): | ||
| name = input('name = ') | ||
| spam = [] | ||
| for j in range(1, 5): | ||
| spam.append(int(input(f'{j} = '))) | ||
| spam = [int(input(f'{j} = ')) for j in range(1, 5)] | ||
|
Comment on lines
-7
to
+9
Author
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. Lines
|
||
| all_comp.append(Comp(name, *spam, sum(spam))) | ||
|
|
||
| print(all_comp) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| even += 1 | ||
| else: | ||
| odd += 1 | ||
| num = num // 10 | ||
| num //= 10 | ||
|
Author
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. Lines
|
||
|
|
||
| print(sys.getsizeof(even)) | ||
| print(sys.getsizeof(odd)) | ||
|
|
@@ -29,7 +29,7 @@ | |
| even += 1 | ||
| else: | ||
| odd += 1 | ||
| num = num // 10 | ||
| num //= 10 | ||
|
|
||
| sum_ += sys.getsizeof(even) | ||
| sum_ += sys.getsizeof(odd) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ def bubble_sort_upd(orig_list): | |
| return orig_list | ||
|
|
||
|
|
||
| orig_list = [random.randint(-100, 100) for i in range(10)] | ||
| orig_list = [random.randint(-100, 100) for _ in range(10)] | ||
|
Author
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. Lines
|
||
|
|
||
| print(timeit.timeit("bubble_sort(orig_list)", setup="from __main__ import bubble_sort, orig_list", number=1000000)) | ||
| print(timeit.timeit("bubble_sort_upd(orig_list)", setup="from __main__ import bubble_sort_upd, orig_list", number=1000000)) | ||
|
|
||
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.
Lines
17-17refactored with the following changes:aug-assign)