Skip to content

Conversation

@Olga888-56
Copy link

No description provided.

Copy link

@alexandrettio alexandrettio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошо! Есть задание в котором надо подстроиться под текст условия, и поправить соотношение мальчиков и девочек в классе

В остальном корректно и аккуратно выполненная работа по циклам, словарям и строкам. Так держать

'Вася': True,
'Маша': False,
}
names = ['Оля', 'Петя', 'Вася', 'Маша']

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):

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():

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]

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}')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, как раз тот вопрос который задавала в тг. Тут получается мы выведем только для последнего класса. Потому что значения переменных пересчитываем в цикле, а выводим уже за пределами цикла

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants