-
Notifications
You must be signed in to change notification settings - Fork 262
Problem solution #30
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?
Problem solution #30
Changes from 15 commits
0f1e138
1c8d7d0
88169bb
190192d
85ef5fb
c27c417
dd92056
c63c919
b3ba249
867a711
991276a
7ff8a37
1a2b535
d7696ae
1a9d3bc
2c3c060
0563d48
f4da86c
9b7131c
0b79ba6
7598ae9
fb5366d
191c915
3cc58b3
3aa9ea8
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,118 @@ | ||
| """ | ||
| В этот раз у нас есть компания, в ней отделы, в отделах люди. У людей есть имя, должность и зарплата. | ||
| Ваши задачи такие: | ||
| 1. Вывести названия всех отделов | ||
| 2. Вывести имена всех сотрудников компании. | ||
| 3. Вывести имена всех сотрудников компании с указанием отдела, в котором они работают. | ||
| 4. Вывести имена всех сотрудников компании, которые получают больше 100к. | ||
| 5. Вывести позиции, на которых люди получают меньше 80к (можно с повторениями). | ||
| 6. Посчитать, сколько денег в месяц уходит на каждый отдел – и вывести вместе с названием отдела | ||
|
|
||
| Второй уровень: | ||
| 7. Вывести названия отделов с указанием минимальной зарплаты в нём. | ||
| 8. Вывести названия отделов с указанием минимальной, средней и максимальной зарплаты в нём. | ||
| 9. Вывести среднюю зарплату по всей компании. | ||
| 10. Вывести названия должностей, которые получают больше 90к без повторений. | ||
| 11. Посчитать среднюю зарплату по каждому отделу среди девушек (их зовут Мишель, Николь, Кристина и Кейтлин). | ||
| 12. Вывести без повторений имена людей, чьи фамилии заканчиваются на гласную букву. | ||
| """ | ||
|
|
||
| departments = [ | ||
| { | ||
| "title": "HR department", | ||
| "employers": [ | ||
| {"first_name": "Daniel", "last_name": "Berger", "position": "Junior HR", "salary_rub": 50000}, | ||
| {"first_name": "Michelle", "last_name": "Frey", "position": "Middle HR", "salary_rub": 75000}, | ||
| {"first_name": "Kevin", "last_name": "Jimenez", "position": "Middle HR", "salary_rub": 70000}, | ||
| {"first_name": "Nicole", "last_name": "Riley", "position": "HRD", "salary_rub": 120000}, | ||
| ] | ||
| }, | ||
| { | ||
| "title": "IT department", | ||
| "employers": [ | ||
| {"first_name": "Christina", "last_name": "Walker", "position": "Python dev", "salary_rub": 80000}, | ||
| {"first_name": "Michelle", "last_name": "Gilbert", "position": "JS dev", "salary_rub": 85000}, | ||
| {"first_name": "Caitlin", "last_name": "Bradley", "position": "Teamlead", "salary_rub": 950000}, | ||
| {"first_name": "Brian", "last_name": "Hartman", "position": "CTO", "salary_rub": 130000}, | ||
| ] | ||
| }, | ||
| ] | ||
|
|
||
| for department in departments: # task 1 | ||
| print(department['title']) | ||
|
|
||
| for department in departments: # task 2 | ||
| for employer in department['employers']: | ||
| print(employer['first_name']) | ||
|
|
||
| for department in departments: # task 3 | ||
| for employer in department['employers']: | ||
| print(f'{employer["first_name"]} работает в {department["title"]}') | ||
|
|
||
| task_salary = 100000 # task 4 | ||
| for department in departments: | ||
| for employer in department['employers']: | ||
| if employer['salary_rub'] > task_salary: | ||
| print(f'Заработная плата {employer["first_name"]} превышает {task_salary}К') | ||
|
|
||
| task_salary = 80000 # task 5 | ||
| for department in departments: | ||
| for employer in department['employers']: | ||
| if employer['salary_rub'] < task_salary: | ||
| print(f'Заработная плата {employer["position"]} ниже {task_salary}К') | ||
|
|
||
| for department in departments: # task 6 | ||
| department_salary = 0 | ||
| for employer in department['employers']: | ||
| department_salary += employer['salary_rub'] | ||
| print(f'Заработная плата {department["title"]} в месяц составляет {department_salary}') | ||
|
|
||
| for department in departments: # task 7 | ||
| department_salary = [] | ||
| for employer in department['employers']: | ||
| department_salary.append(employer['salary_rub']) | ||
| print(f'Отдел {department["title"]} - минимальная зарплата {min(department_salary)}') | ||
|
|
||
| for department in departments: # task 8 | ||
| department_salary = [] | ||
| avg_salary = 0 | ||
| for employer in department['employers']: | ||
| department_salary.append(employer['salary_rub']) | ||
| avg_salary = sum(department_salary) / len(department_salary) | ||
| min_salary = min(department_salary) | ||
| max_salary = max(department_salary) | ||
| print(f'Отдел {department["title"]}: минимальная зарплата {min_salary}') | ||
| print(f'Отдел {department["title"]}: максимальная зарплата {max_salary}') | ||
| print(f'Отдел {department["title"]}: cредняя зарплата {int(avg_salary)}') | ||
|
|
||
| salary = [] # task 9 | ||
| for department in departments: | ||
| for employer in department['employers']: | ||
| salary.append(employer['salary_rub']) | ||
| avg_salary = sum(salary) / len(salary) | ||
| print(f'Средняя зарплата компании {avg_salary}') | ||
|
|
||
| task_salary = 90000 # task 10 | ||
| salary_cap = [] | ||
| for department in departments: | ||
| for employer in department['employers']: | ||
| if employer['salary_rub'] > task_salary: | ||
| salary_cap.append(employer["position"]) | ||
| print(f'{", ".join(salary_cap)} получают больше {task_salary}К') | ||
|
|
||
| girls = ['Michelle', 'Nicole', 'Christina', 'Caitlin'] # task 11 | ||
| for department in departments: | ||
| girl_salary = [] | ||
| for employer in department['employers']: | ||
| if employer['first_name'] in girls: | ||
| girl_salary.append(employer['salary_rub']) | ||
| avg_girls_salary = sum(girl_salary) / len(girl_salary) | ||
| print(f'Средняя зарплата девушек по {department["title"]} составляет: {int(avg_girls_salary)}') | ||
|
|
||
| end_vowel_letter_in_last_name = [] # task 12 | ||
| for department in departments: | ||
| for employer in department['employers']: | ||
| if employer['last_name'][-1] in 'aeiouy': | ||
| end_vowel_letter_in_last_name.append(employer["first_name"]) | ||
| end_vowel_letter_in_last_name_set = set(end_vowel_letter_in_last_name) | ||
| print(f'Фамилии сотрудников {", ".join(end_vowel_letter_in_last_name_set)} оканчиваются на гласную букву') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,12 @@ | |
| {'first_name': 'Маша'}, | ||
| {'first_name': 'Петя'}, | ||
| ] | ||
| # ??? | ||
|
|
||
| name_of_students = [student['first_name'] for student in students] | ||
| uniq_name = list(set(name_of_students)) | ||
|
|
||
| for name in uniq_name: | ||
| print(f'{name}: {name_of_students.count(name)}') | ||
|
|
||
| # Задание 2 | ||
| # Дан список учеников, нужно вывести самое часто повторящееся имя | ||
|
|
@@ -26,8 +30,29 @@ | |
| {'first_name': 'Маша'}, | ||
| {'first_name': 'Оля'}, | ||
| ] | ||
| # ??? | ||
|
|
||
| def max_name(students): | ||
| name_of_students = [student['first_name'] for student in students] | ||
|
|
||
| names_counter = dict() | ||
| for name in name_of_students: | ||
| if names_counter.get(name): | ||
| names_counter[name] += 1 | ||
| else: | ||
| names_counter[name] = 1 | ||
|
|
||
| max_names = [] | ||
| max_count = 0 | ||
|
|
||
| for name, count_of_name in names_counter.items(): | ||
|
Contributor
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. Почитай про функцию max и её аргументы, у тебя может получиться заменить весь этот цикл правильным её использованием. |
||
| if count_of_name > max_count: | ||
| max_count = count_of_name | ||
| max_names = [name] | ||
| elif count_of_name == max_count: | ||
| max_names.append(name) | ||
| return f'Самое частое имя среди учеников: {"".join(max_names)}' | ||
|
|
||
| print(max_name(students)) | ||
|
|
||
| # Задание 3 | ||
| # Есть список учеников в нескольких классах, нужно вывести самое частое имя в каждом классе. | ||
|
|
@@ -51,13 +76,13 @@ | |
| {'first_name': 'Саша'}, | ||
| ], | ||
| ] | ||
| # ??? | ||
|
|
||
| for name in school_students: | ||
| print(max_name(name)) | ||
|
|
||
| # Задание 4 | ||
| # Для каждого класса нужно вывести количество девочек и мальчиков в нём. | ||
| # Пример вывода: | ||
| # Класс 2a: девочки 2, мальчики 0 | ||
| # Класс 2a: девочки 2, мальчики 0 | ||
| # Класс 2б: девочки 0, мальчики 2 | ||
|
|
||
| school = [ | ||
|
|
@@ -72,7 +97,16 @@ | |
| 'Миша': True, | ||
| 'Даша': False, | ||
| } | ||
| # ??? | ||
|
|
||
| for students in school: | ||
| male_gender = 0 | ||
| female_gender = 0 | ||
| for name in students['students']: | ||
| if is_male.get(name['first_name']): | ||
| male_gender += 1 | ||
| else: | ||
| female_gender += 1 | ||
| print(f'Класс {students["class"]}: девочки {female_gender}, мальчики {male_gender}') | ||
|
|
||
|
|
||
| # Задание 5 | ||
|
|
@@ -91,5 +125,29 @@ | |
| 'Олег': True, | ||
| 'Миша': True, | ||
| } | ||
| # ??? | ||
|
|
||
| max_male_class = '' | ||
| max_female_class = '' | ||
|
Contributor
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. Пока у тебя нет таких классов, в эти переменные стоит записывать None – его в пайтоне как раз для этого и придумали. |
||
| max_male_gender = 0 | ||
| max_female_gender = 0 | ||
|
|
||
| for students in school: | ||
|
Contributor
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. Тут не students, тут класс типа. |
||
| male_gender = 0 | ||
| female_gender = 0 | ||
| for name in students['students']: | ||
| if is_male.get(name['first_name']): | ||
| male_gender += 1 | ||
| else: | ||
| female_gender += 1 | ||
| if male_gender > female_gender: | ||
|
Contributor
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. Кажется, у этого ифа лишний отступ |
||
| max_male_gender = male_gender | ||
| max_male_class = str(students["class"]) | ||
|
Contributor
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. students["class"] и так строка, не надо её ещё раз превращать в строку. |
||
| if male_gender > max_male_gender: | ||
| max_male_gende = male_gender | ||
| else: | ||
| max_female_gender = female_gender | ||
| max_female_class = str(students["class"]) | ||
| if female_gender > max_female_gender: | ||
| max_female_gender = female_gender | ||
| print(f'Больше всего мальчиков в классе {max_male_class}') | ||
| print(f'Больше всего девочек в классе {max_female_class}') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,36 @@ | ||
| # Вывести последнюю букву в слове | ||
| word = 'Архангельск' | ||
| # ??? | ||
| print(word[-1]) | ||
|
|
||
|
|
||
| # Вывести количество букв "а" в слове | ||
| word = 'Архангельск' | ||
| # ??? | ||
| print(word.lower().count('а')) | ||
|
|
||
|
|
||
| # Вывести количество гласных букв в слове | ||
| word = 'Архангельск' | ||
| # ??? | ||
|
|
||
| vowel_letters = 'аеёиоуыэюя' | ||
| count_vowel_letters = 0 | ||
| for letters in word.lower(): | ||
| if letters in vowel_letters: | ||
| count_vowel_letters += 1 | ||
| print(f'Количество гласных букв в слове {word}: {count_vowel_letters}') | ||
|
|
||
| # Вывести количество слов в предложении | ||
| sentence = 'Мы приехали в гости' | ||
| # ??? | ||
|
|
||
| word_count = sentence.count(' ') + 1 | ||
| print(f'Количество слов в предложении: {word_count}') | ||
|
|
||
| # Вывести первую букву каждого слова на отдельной строке | ||
| sentence = 'Мы приехали в гости' | ||
| # ??? | ||
|
|
||
| for word in sentence.split(): | ||
| print(word[0]) | ||
|
|
||
| # Вывести усреднённую длину слова в предложении | ||
| sentence = 'Мы приехали в гости' | ||
| # ??? | ||
| len_word = 0 | ||
| for word in sentence.split(): | ||
| len_word += len(word) | ||
| avg_len_word = len_word / len(sentence.split()) | ||
| print(avg_len_word) |
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.
Теперь K из принта надо убрать, а то получается, что там теперь 100000к. Аналогично принтами ниже.