-
Notifications
You must be signed in to change notification settings - Fork 260
Вторая домашка basic_exercises #59
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?
Conversation
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.
Хорошо! Есть задание в котором надо подстроиться под текст условия, и поправить соотношение мальчиков и девочек в классе
В остальном корректно и аккуратно выполненная работа по циклам, словарям и строкам. Так держать
@@ -25,6 +27,10 @@ | |||
'Маша': False, | |||
} | |||
names = ['Оля', 'Петя', 'Вася', 'Маша'] |
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.
Текущий код рабочий, но немного не ту задачу решает.
Нам надо пройтись по списку имен и для каждого из этих имен написать пол ученика
Можно предположить что в is_male сотни имен, а нам надо узнать только про те имена с которыми мы сталкиваемся в группе
count_groups = len(groups) | ||
print(f"Всего {count_groups} группы") | ||
|
||
for group_number,group in enumerate(groups, start = 1): |
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.
отлично! Отдельно хвалю за выбор имен переменных и использование enumerate
names = dict() | ||
|
||
for student in students: | ||
if student['first_name'] not in names.keys(): |
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.
Так как мы работаем со словарем лучше сделать проверку
if student['first_name'] not in names:
Она будет работать быстрее чем
if student['first_name'] not in names.keys():
Изменения по скорости на таком маленьком объеме мы не заметим, но общий подход запомнить полезно. Для словаря наличие ключа проверяем внутри словаря, а не внутри списка ключей словаря
|
||
class_num = 1 | ||
for item in school_students: | ||
temp = [name['first_name'] for name in item] |
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.
Здорово получилось собрать список имен из списка словарей! Горжусь тем, что ты нашла это решение
else: | ||
girls +=1 | ||
|
||
print(f'Класс {class_name}: девочки {girls}, мальчики {boys}') |
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.
Да, как раз тот вопрос который задавала в тг. Тут получается мы выведем только для последнего класса. Потому что значения переменных пересчитываем в цикле, а выводим уже за пределами цикла
No description provided.