-
Notifications
You must be signed in to change notification settings - Fork 0
lesson 5 #7
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: lesson-1
Are you sure you want to change the base?
lesson 5 #7
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #Пользователь вводит данные о количестве предприятий, их наименования | ||
| # и прибыль за 4 квартала для каждого предприятия. | ||
| # Программа должна определить среднюю прибыль (за год для всех предприятий) | ||
| # и вывести наименования предприятий, чья прибыль выше среднего | ||
| # и отдельно вывести наименования предприятий, чья прибыль ниже среднего. | ||
|
|
||
| #! Ничего не сказано про компании с годовой прибылью равной среднему. | ||
| # Отнес их к "хорошим". | ||
|
|
||
| from collections import namedtuple | ||
|
|
||
| numbers_of_company = int(input('Введите количество компаний: ')) | ||
| if numbers_of_company == 0: | ||
| print('Работникам ПВО большой привет!') | ||
| else: | ||
| companies = [] | ||
| full_summ = 0 | ||
| company = namedtuple('company','name, years_profit') | ||
|
|
||
| for i in range(numbers_of_company): | ||
|
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. Если в этом цикле i, то во вложенном пишите j |
||
| company_name = (str(input(f'Введите название компании {i + 1}:'))) | ||
| year_summ = quarter_summ = 0 | ||
| for i in range(4): | ||
|
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.
|
||
| quarter_profit = int(input( | ||
| f'Введите ее прибыль за {i + 1} квартал: ')) | ||
| year_summ += quarter_profit | ||
| full_summ += quarter_profit | ||
| companies.append(company(company_name, year_summ)) | ||
| average_summ = full_summ / numbers_of_company | ||
|
|
||
| good_company = [] | ||
| bad_company = [] | ||
|
|
||
| for comp in companies: | ||
| if comp.years_profit >= average_summ: | ||
| good_company.append(comp.name) | ||
| else: | ||
| bad_company.append(comp.name) | ||
|
|
||
| print('Средняя сумма составила:', int(average_summ)) | ||
| print('Компании с прибылью выше среднего:') | ||
| print(*good_company, sep=', ') | ||
| print('Koмпании с прибылью ниже среднего:') | ||
| print(*bad_company, sep=', ') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #Написать программу сложения и умножения двух шестнадцатеричных чисел. | ||
| #При этом каждое число представляется как массив, | ||
| # элементы которого это цифры числа. | ||
|
|
||
|
|
||
| from collections import deque | ||
|
|
||
|
|
||
| def input_numbers(): | ||
| num = str(input('Введите шестнадцатиричное число: ')) | ||
| numbers = list(deque(num)) #т.к. по условию задачи хранить | ||
|
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. Речь шла о массиве. |
||
| #нужно в простом списке | ||
| return list(numbers) | ||
|
|
||
|
|
||
| def read_numbers(numbers): | ||
| values = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15} | ||
| s = 0 | ||
| k = 0 | ||
| for i in range(len(numbers)): | ||
| if numbers[i] in values: | ||
| s = values[numbers[i]] | ||
| else: | ||
| s = int(numbers[i]) | ||
| k += s * 16 ** (len(numbers) - 1 - i) | ||
| return k | ||
|
|
||
|
|
||
| def make_hexadecimal(num): | ||
| num = int(num) | ||
| values = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'} | ||
| result = deque([]) | ||
| while num // 16 and num % 16 != 0: | ||
| k = num % 16 | ||
| if k in values: | ||
| result.appendleft(str(values[k])) | ||
| else: | ||
| result.appendleft(str(k)) | ||
| num = num // 16 | ||
| if num in values: | ||
| result.appendleft(str(values[num])) | ||
| elif num != 0: | ||
| result.appendleft(str(num)) | ||
| return list(result) | ||
|
|
||
|
|
||
| def print_numbers(num): | ||
| str_num = str() | ||
| for i in num: | ||
| str_num += i | ||
| return str_num | ||
|
|
||
|
|
||
| print('Последовательно введите два шестнадцатиричных числа') | ||
| first_number = input_numbers() | ||
| second_number = input_numbers() | ||
| summ_numbers = make_hexadecimal(read_numbers(first_number) + | ||
|
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. Не совсем в столбик. Скорее даже в строку, а не в столбик. |
||
| read_numbers(second_number)) | ||
| multiplication_numbers = make_hexadecimal(read_numbers(first_number) * | ||
| read_numbers(second_number)) | ||
| #print(summ_numbers, multiplication_numbers) | ||
| print('Сумма введеных чисел в шестнадцатиричной системе: ', | ||
| print_numbers(summ_numbers)) | ||
| #print('Сумма введенных шестнадцатиричных чисел в десятичной системе: ', | ||
| # read_numbers(summ_numbers)) | ||
| print('Произведение введеных чисел в шестнадцатиричной системе: ', | ||
| print_numbers(multiplication_numbers)) | ||
|
|
||
| #print('Произведение введенных шестнадцатиричных чисел составит в десятичной системе: ', | ||
| # read_numbers( multiplication_numbers)) | ||
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.
Почему именно ПВО? )))