-
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
Open
Chernykh-a-s
wants to merge
25
commits into
learnpythonru:main
Choose a base branch
from
Chernykh-a-s:problem_solution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Problem solution #30
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0f1e138
basic_exercises part 1
1c8d7d0
basic_exercises fixed
88169bb
basic_exercises fixed_1
190192d
add string_challenges.py, for_challenges.py fixed
85ef5fb
add for_dict_challenges.py
c27c417
for_challenges.py, string_challenges.py fixed
dd92056
add task company.py solution
c63c919
add task company.py solution
b3ba249
company.py fixed, add additional tasks
867a711
fixed compane.py
991276a
fixed company.py, for_dict_challenges.py +last task
7ff8a37
fixed company.py
1a2b535
fixed for_dict_challenges.py, except for the 5 task
d7696ae
fixed company.py, for_dict_challenges.py
1a9d3bc
fixed for_challenges.py, string_challenges.py
2c3c060
correcting remarks code review company.py, for_dict_challenges.py
0563d48
add task 13, 14 company
f4da86c
correcting task 13, add functions
9b7131c
fixed 13, 14 tasks
0b79ba6
Исправил замечания, добавил решения задач 16,17,18
7598ae9
Решение 1 задачи в for_dict_challenges_bonus.py
fb5366d
исправление замечаний review
191c915
исправление замечаний, немного поменял алгоритм
3cc58b3
fixing the mistakes according to the comments
3aa9ea8
Решение 2 задачи \for_dict_challenges_bonus.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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)} оканчиваются на гласную букву') |
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
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
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
| 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) |
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.
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.
Почитай про функцию max и её аргументы, у тебя может получиться заменить весь этот цикл правильным её использованием.