-
Notifications
You must be signed in to change notification settings - Fork 259
for_challenges и for_dict_challenges на проверку #42
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?
Changes from 4 commits
a9e8691
ddaa3e4
a90923a
4f42a44
1fc6c28
bda67dd
c4f3907
8ca0a4a
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 @@ | ||
| env/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |
| # Необходимо вывести имена всех учеников из списка с новой строки | ||
|
|
||
| names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
| # ??? | ||
| print('\nЗадание 1') | ||
| [print(name) for name in names] | ||
|
|
||
|
|
||
| # Задание 2 | ||
|
|
@@ -12,7 +13,8 @@ | |
| # Петя: 4 | ||
|
|
||
| names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
| # ??? | ||
| print('\nЗадание 2') | ||
| [print(f'{name}: {len(name)}') for name in names] | ||
|
Maksimous777 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| # Задание 3 | ||
|
|
@@ -24,8 +26,16 @@ | |
| 'Вася': True, | ||
| 'Маша': False, | ||
| } | ||
| names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
| # ??? | ||
| names = ['Оля', 'Петя', 'Вася', 'Маша', 'Максим'] | ||
| print('\nЗадание 3') | ||
| for name in names: | ||
| try: | ||
| if is_male[name]: | ||
| print(f'{name}: Мужской') | ||
| else: | ||
| print(f'{name}: Женский') | ||
| except KeyError: | ||
| print(f'Не знаю такого имени: {name}') | ||
|
Comment on lines
+32
to
+38
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. #42 (comment) |
||
|
|
||
|
|
||
| # Задание 4 | ||
|
|
@@ -40,7 +50,10 @@ | |
| ['Вася', 'Маша', 'Саша', 'Женя'], | ||
| ['Оля', 'Петя', 'Гриша'], | ||
| ] | ||
| # ??? | ||
| print('\nЗадание 4') | ||
| print(f'Всего {len(groups)} группы') | ||
| for index, group in enumerate(groups, start=1): | ||
| print(f"Группа {index}: {len(group)} ученика") | ||
|
|
||
|
|
||
| # Задание 5 | ||
|
|
@@ -54,4 +67,6 @@ | |
| ['Оля', 'Петя', 'Гриша'], | ||
| ['Вася', 'Маша', 'Саша', 'Женя'], | ||
| ] | ||
| # ??? | ||
| print('\nЗадание 5') | ||
| [print(f"Группа {index}: {', '.join(group)}") | ||
| for index, group in enumerate(groups, start=1)] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from collections import Counter | ||
| # Задание 1 | ||
| # Дан список учеников, нужно посчитать количество повторений каждого имени ученика | ||
| # Пример вывода: | ||
|
|
@@ -12,7 +13,12 @@ | |
| {'first_name': 'Маша'}, | ||
| {'first_name': 'Петя'}, | ||
| ] | ||
| # ??? | ||
|
|
||
| print('Задание 1') | ||
| qty_students = (Counter(student['first_name'] for student in students)) | ||
| for student in qty_students: | ||
| print(f'{student}: {qty_students[student]}') | ||
| print() | ||
|
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. Fair enough. |
||
|
|
||
|
|
||
| # Задание 2 | ||
|
|
@@ -26,7 +32,12 @@ | |
| {'first_name': 'Маша'}, | ||
| {'first_name': 'Оля'}, | ||
| ] | ||
| # ??? | ||
|
|
||
| print('Задание 2') | ||
| most_common_student = Counter(student['first_name'] | ||
| for student in students).most_common(1) | ||
| print( | ||
| f'Самое частое имя среди учеников: {most_common_student[0][0]}\n') | ||
|
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. Хорошо! |
||
|
|
||
|
|
||
| # Задание 3 | ||
|
|
@@ -44,26 +55,35 @@ | |
| {'first_name': 'Маша'}, | ||
| {'first_name': 'Маша'}, | ||
| {'first_name': 'Оля'}, | ||
| ],[ # это – третий класс | ||
| ], [ # это – третий класс | ||
| {'first_name': 'Женя'}, | ||
| {'first_name': 'Петя'}, | ||
| {'first_name': 'Женя'}, | ||
| {'first_name': 'Саша'}, | ||
| ], | ||
| ] | ||
| # ??? | ||
|
|
||
| print('Задание 3') | ||
| for grade in range(len(school_students)): | ||
| max_students = Counter(student['first_name'] | ||
| for student in school_students[grade]).most_common(1) | ||
| print( | ||
| f'Самое частое имя в классе {grade + 1}: {max_students[0][0]}') | ||
| print() | ||
|
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. 👍 |
||
|
|
||
| # Задание 4 | ||
| # Для каждого класса нужно вывести количество девочек и мальчиков в нём. | ||
| # Пример вывода: | ||
| # Класс 2a: девочки 2, мальчики 0 | ||
| # Класс 2a: девочки 2, мальчики 0 | ||
| # Класс 2б: девочки 0, мальчики 2 | ||
|
|
||
| school = [ | ||
| {'class': '2a', 'students': [{'first_name': 'Маша'}, {'first_name': 'Оля'}]}, | ||
| {'class': '2б', 'students': [{'first_name': 'Олег'}, {'first_name': 'Миша'}]}, | ||
| {'class': '2б', 'students': [{'first_name': 'Даша'}, {'first_name': 'Олег'}, {'first_name': 'Маша'}]}, | ||
| {'class': '2a', 'students': [ | ||
| {'first_name': 'Маша'}, {'first_name': 'Оля'}]}, | ||
| {'class': '2б', 'students': [ | ||
| {'first_name': 'Олег'}, {'first_name': 'Миша'}]}, | ||
| {'class': '2б', 'students': [{'first_name': 'Даша'}, { | ||
| 'first_name': 'Олег'}, {'first_name': 'Маша'}]}, | ||
| ] | ||
| is_male = { | ||
| 'Олег': True, | ||
|
|
@@ -72,24 +92,51 @@ | |
| 'Миша': True, | ||
| 'Даша': False, | ||
| } | ||
| # ??? | ||
|
|
||
|
|
||
| print('Задание 4') | ||
| for grade in school: | ||
| male = 0 | ||
| female = 0 | ||
| for student in grade['students']: | ||
| if is_male[student['first_name']]: | ||
| male += 1 | ||
| else: | ||
| female += 1 | ||
| print( | ||
| f"Класс {grade['class']}: девочки {female}, мальчики {male}") | ||
| print() | ||
|
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. 👍 |
||
| # Задание 5 | ||
| # По информации о учениках разных классов нужно найти класс, в котором больше всего девочек и больше всего мальчиков | ||
| # Пример вывода: | ||
| # Больше всего мальчиков в классе 3c | ||
| # Больше всего девочек в классе 2a | ||
|
|
||
| school = [ | ||
| {'class': '2a', 'students': [{'first_name': 'Маша'}, {'first_name': 'Оля'}]}, | ||
| {'class': '3c', 'students': [{'first_name': 'Олег'}, {'first_name': 'Миша'}]}, | ||
| {'class': '2a', 'students': [ | ||
| {'first_name': 'Маша'}, {'first_name': 'Оля'}]}, | ||
| {'class': '3c', 'students': [ | ||
| {'first_name': 'Олег'}, {'first_name': 'Миша'}]}, | ||
| ] | ||
| is_male = { | ||
| 'Маша': False, | ||
| 'Оля': False, | ||
| 'Олег': True, | ||
| 'Миша': True, | ||
| } | ||
| # ??? | ||
| print('Задание 5') | ||
| male = [] | ||
| female = [] | ||
| for grade in range(len(school)): | ||
| male.append(0) | ||
| female.append(0) | ||
| for student in school[grade]['students']: | ||
| if is_male[student['first_name']]: | ||
| male[grade] += 1 | ||
| else: | ||
| female[grade] += 1 | ||
|
|
||
| most_male = school[male.index(max(male))]['class'] | ||
|
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. тут мне кажется усложненно. Я бы предложила переделать через хранение доппеременных. Макс_число мальчиков + класс в котором это число и аналогично для девочек. На таких объемах это по длительности работы программы будет неотличимо. Но если мы говорим условно обо всех классах москвы, то уже разница будет ощутима |
||
| most_female = school[female.index(max(female))]['class'] | ||
| print( | ||
| f"Больше всего мальчиков в классе {most_male}") | ||
| print( | ||
| f"Больше всего девочек в классе {most_female}") | ||
Uh oh!
There was an error while loading. Please reload this page.