Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
21 changes: 16 additions & 5 deletions for_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Необходимо вывести имена всех учеников из списка с новой строки

names = ['Оля', 'Петя', 'Вася', 'Маша']
# ???
for i in names:
print(f'{i}\n')


# Задание 2
Expand All @@ -12,7 +13,8 @@
# Петя: 4

names = ['Оля', 'Петя', 'Вася', 'Маша']
# ???
for i in names:
print(f'{i}: {len(i)}\n')


# Задание 3
Expand All @@ -25,8 +27,12 @@
'Маша': False,
}
names = ['Оля', 'Петя', 'Вася', 'Маша']
# ???

for i in names:
if i in is_male and is_male[i] == True:
print(f'{i}: М')
else:
print(f'{i}: Ж')

# Задание 4
# Даны группу учеников. Нужно вывести количество групп и для каждой группы – количество учеников в ней
Expand All @@ -40,8 +46,10 @@
['Вася', 'Маша', 'Саша', 'Женя'],
['Оля', 'Петя', 'Гриша'],
]
# ???

print(f'Всего групп: {len(groups)}')
for i in range(len(groups)):
print(f'Группа {i+1}: {len(groups[i])} ученика')

# Задание 5
# Для каждой пары учеников нужно с новой строки перечислить учеников, которые в неё входят
Expand All @@ -54,4 +62,7 @@
['Оля', 'Петя', 'Гриша'],
['Вася', 'Маша', 'Саша', 'Женя'],
]
# ???

for i in range(len(groups)):
names = ', '.join(groups[i])
print(f'Группа {i + 1}: {names}')
94 changes: 89 additions & 5 deletions for_dict_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
{'first_name': 'Маша'},
{'first_name': 'Петя'},
]
# ???

counts = {}
for i in students:
name = i['first_name']
if name in counts:
counts[name] += 1
else:
counts[name] = 1

for j in counts:
print(f'{j}: {counts[j]}')



# Задание 2
Expand All @@ -26,7 +37,22 @@
{'first_name': 'Маша'},
{'first_name': 'Оля'},
]
# ???

max_name = None
max_count = 0

def find_most_common_name(counts):
max_name = None
max_count = 0

for name in counts:
if counts[name] > max_count:
max_name = name
max_count = counts[name]

print(f'Самое частое имя: {max_name} ({max_count})')

find_most_common_name(counts)


# Задание 3
Expand All @@ -51,8 +77,26 @@
{'first_name': 'Саша'},
],
]
# ???

for i in range(len(school_students)):
class_students = school_students[i]
name_counts = {}

for student in class_students:
name = student['first_name']
if name in name_counts:
name_counts[name] += 1
else:
name_counts[name] = 1

most_common_name = ''
max_count = 0
for name in name_counts:
if name_counts[name] > max_count:
max_count = name_counts[name]
most_common_name = name

print(f'Самое частое имя в классе {i + 1}: {most_common_name}')

# Задание 4
# Для каждого класса нужно вывести количество девочек и мальчиков в нём.
Expand All @@ -72,7 +116,20 @@
'Миша': True,
'Даша': False,
}
# ???
for class_info in school:
class_name = class_info['class']
students = class_info['students']
boys = 0
girls = 0

for student in students:
name = student['first_name']
if is_male[name]:
boys += 1
else:
girls += 1

print(f'Класс {class_name}: девочки {girls}, мальчики {boys}')


# Задание 5
Expand All @@ -91,5 +148,32 @@
'Олег': True,
'Миша': True,
}
# ???

max_boys = 0
class_with_most_boys = ''
max_girls = 0
class_with_most_girls = ''

for class_info in school:
class_name = class_info['class']
boys = 0
girls = 0

for student in class_info['students']:
name = student['first_name']
if is_male[name]:
boys += 1
else:
girls += 1

if boys > max_boys:
max_boys = boys
class_with_most_boys = class_name

if girls > max_girls:
max_girls = girls
class_with_most_girls = class_name

print(f'Больше всего мальчиков в классе {class_with_most_boys}')
print(f'Больше всего девочек в классе {class_with_most_girls}')

3 changes: 3 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
buy bread
learn python
take a walk
Loading