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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions for_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
}
names = ['Оля', 'Петя', 'Вася', 'Маша']
for name in names:
if is_male[name] is False:
if is_male[name]:
print(f"{name}: пол женский.")
elif is_male[name] is True:
else:
print(f"{name}: пол мужской.")

# Задание 4
Expand All @@ -44,6 +44,7 @@
['Вася', 'Маша', 'Саша', 'Женя'],
['Оля', 'Петя', 'Гриша'],
]
print(f"Всего {len(groups)} группы.")
num_group = 0
for group in groups:
num_group += 1
Expand Down
88 changes: 35 additions & 53 deletions for_dict_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
# Дан список учеников, нужно вывести самое часто повторящееся имя
# Пример вывода:
# Самое частое имя среди учеников: Маша

print(" ")
print(" * *" * 10)
students = [
{'first_name': 'Вася'},
{'first_name': 'Петя'},
{'first_name': 'Маша'},
{'first_name': 'Маша'},
{'first_name': 'Оля'},
]
lists = []
for values in students:
lists.append(values['first_name'])
for item in lists:
if lists.count(item) > 1:
print(f"Частое имя среди учеников: {item}.")
break
count_dict = dict()
for name in students:
count_dict[name["first_name"]] = students.count(name)
print("Самое частое имя среди учеников:", max(count_dict, key=count_dict.get))


# Задание 3
Expand All @@ -43,6 +43,8 @@
# Самое частое имя в классе 1: Вася
# Самое частое имя в классе 2: Маша

print(" ")
print(" * *" * 10)
school_students = [
[ # это – первый класс
{'first_name': 'Вася'},
Expand All @@ -59,22 +61,13 @@
{'first_name': 'Саша'},
],
]
CLASS_NUM_1 = 0
CLASS_NUM_2 = 1
CLASS_NUM_3 = 2

def class_number(school_student, num_class):
list1 = []
for item1 in range(len(school_student[num_class])):
list1.append(school_students[num_class][item1]['first_name'])
for value1 in list1:
if list1.count(value1) > 1:
print(f"Частое имя в классе {num_class + 1}: {value1}.")
break

class_number(school_students, CLASS_NUM_1)
class_number(school_students, CLASS_NUM_2)
class_number(school_students, CLASS_NUM_3)
def popular_name(students):
count_dict = dict()
for name in students:
count_dict[name["first_name"]] = students.count(name)
return max(count_dict, key=count_dict.get)
for students in school_students:
print(f"Самое частое имя в классе {school_students.index(students) + 1}: {popular_name(students)}.")


# Задание 4
Expand All @@ -83,6 +76,8 @@ def class_number(school_student, num_class):
# Класс 2a: девочки 2, мальчики 0
# Класс 2б: девочки 0, мальчики 2

print(" ")
print(" * *" * 10)
school = [
{'class': '2a', 'students': [{'first_name': 'Маша'}, {'first_name': 'Оля'}]},
{'class': '2б', 'students': [{'first_name': 'Олег'}, {'first_name': 'Миша'}]},
Expand All @@ -95,31 +90,25 @@ def class_number(school_student, num_class):
'Миша': True,
'Даша': False,
}
CLASS_2A = 0
CLASS_2B = 1
CLASS_2V = 2

def name_list(school1, class_num, is_mal):
for class_num in school:
boys = 0
girls = 0
name = school1[class_num]["students"]
for val in name:
if is_mal[val["first_name"]] is False:
girls += 1
elif is_mal[val["first_name"]] is True:
for name in class_num["students"]:
if is_male[name["first_name"]]:
boys += 1
print(f"Класс {school1[class_num]['class']}: девочки {girls}, мальчики {boys}")
else:
girls += 1
print(f"Класс {class_num['class']}: девочки {girls}, мальчики {boys}")

name_list(school,CLASS_2A, is_male)
name_list(school,CLASS_2B, is_male)
name_list(school,CLASS_2V, is_male)

# Задание 5
# По информации о учениках разных классов нужно найти класс, в котором больше всего девочек и больше всего мальчиков
# Пример вывода:
# Больше всего мальчиков в классе 3c
# Больше всего девочек в классе 2a

print(" ")
print(" * *" * 10)
school = [
{'class': '2a', 'students': [{'first_name': 'Маша'}, {'first_name': 'Оля'}]},
{'class': '3c', 'students': [{'first_name': 'Олег'}, {'first_name': 'Миша'}]},
Expand All @@ -130,23 +119,16 @@ def name_list(school1, class_num, is_mal):
'Олег': True,
'Миша': True,
}
CLASS_2A = 0
CLASS_3C = 1

def class_list(school2, class_numb, is_males):
for class_num in school:
boys = 0
girls = 0
name = school2[class_numb]["students"]
for val in name:
if is_males[val["first_name"]] is False:
girls += 1
elif is_males[val["first_name"]] is True:
for name in class_num["students"]:
if is_male[name["first_name"]]:
boys += 1
if girls > boys:
print(f"Больше всего девочек в классе {school2[class_numb]['class']}")
elif boys > girls:
print(f"Больше всего мальчиков в классе {school2[class_numb]['class']}")

class_list(school, CLASS_2A, is_male)
class_list(school, CLASS_3C, is_male)
else:
girls += 1
if boys > girls:
print("Бошьше всего мальчиков в классе", class_num['class'])
else:
print("Больше всего девочек в классе", class_num['class'])

28 changes: 27 additions & 1 deletion for_dict_challenges_bonus.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,31 @@ def generate_chat_history():
return messages




if __name__ == "__main__":
print(generate_chat_history())
dict_chat = generate_chat_history()

def id_user_max_message_sent(messages):
dict_count = {}
for message in messages:
if message["sent_by"] not in dict_count.keys():
dict_count[message["sent_by"]] = 1
else:
dict_count[message["sent_by"]] += 1
print(f"Айди пользователя, который написал больше всего сообщений: {max(dict_count, key=dict_count.get)}")

def id_user_max_message_reply(messages):
dict_count = {}
for message in messages:
if message["reply_for"] is None:
continue
if message["reply_for"] not in dict_count.keys():
dict_count[message["reply_for"]] = 1
else:
dict_count[message["reply_for"]] += 1
print(f"Айди пользователя, на сообщение которого больше всего отвечали: {max(dict_count, key=dict_count.get)}")


id_user_max_message_sent(dict_chat)
id_user_max_message_reply(dict_chat)