From c27e2c9f798b0a0baa274fcfdc37d340326b4d46 Mon Sep 17 00:00:00 2001 From: Stas Petrov Date: Sun, 19 Feb 2023 19:29:25 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- for_challenges.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/for_challenges.py b/for_challenges.py index 997754da..06c2cf01 100644 --- a/for_challenges.py +++ b/for_challenges.py @@ -2,7 +2,12 @@ # Необходимо вывести имена всех учеников из списка с новой строки names = ['Оля', 'Петя', 'Вася', 'Маша'] -# ??? +for name1 in names: + print(name1) +print() +name2 = '\n'.join(names) +print(name2) +print() # Задание 2 @@ -12,8 +17,9 @@ # Петя: 4 names = ['Оля', 'Петя', 'Вася', 'Маша'] -# ??? - +for name3 in names: + print(f'{name3}: {len(name3)}') +print() # Задание 3 # Необходимо вывести имена всех учеников из списка, рядом с именем вывести пол ученика @@ -25,7 +31,13 @@ 'Маша': False, } names = ['Оля', 'Петя', 'Вася', 'Маша'] -# ??? +for name in names: + if is_male[name] == False: + print(f'{name}, женский') + else: + print(f'{name}, мужской') +print() + # Задание 4 @@ -40,7 +52,9 @@ ['Вася', 'Маша', 'Саша', 'Женя'], ['Оля', 'Петя', 'Гриша'], ] -# ??? +for group in range(1,len(groups)+1): + print(f'Группа {group}: {len(groups[group-1])} ученика.') + print() # Задание 5 @@ -54,4 +68,6 @@ ['Оля', 'Петя', 'Гриша'], ['Вася', 'Маша', 'Саша', 'Женя'], ] -# ??? \ No newline at end of file +for name in range(len(groups)): + names = ', '.join(groups[name]) + print(f'Группа{name+1}: {names}') \ No newline at end of file From d69332f1bd921cafabff83f55d68fb64d33df6c3 Mon Sep 17 00:00:00 2001 From: Stas Petrov Date: Sun, 19 Feb 2023 19:31:16 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..24951b39 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Module", + "type": "python", + "request": "launch", + "module": "for_challenges", + "justMyCode": true, + "console": "internalConsole" + } + ] +} \ No newline at end of file From 981840c4fd80fc19577beacd789e548901a8a066 Mon Sep 17 00:00:00 2001 From: Stas Petrov Date: Mon, 20 Feb 2023 10:00:45 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B8=D0=BB=D0=BE=D1=81=D1=8C=20=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BD=D0=BE=D0=B2=D1=83=D1=8E=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D0=BA=D1=83,=20=D0=BA=D0=B8=D0=B4=D0=B0=D1=8E=20?= =?UTF-8?q?=D1=81=D1=8E=D0=B4=D0=B0=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- for_dict_challenges.py | 85 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 5 deletions(-) diff --git a/for_dict_challenges.py b/for_dict_challenges.py index 96062ebc..72703a6b 100644 --- a/for_dict_challenges.py +++ b/for_dict_challenges.py @@ -12,8 +12,19 @@ {'first_name': 'Маша'}, {'first_name': 'Петя'}, ] -# ??? +def diction_name_count(lis): + repeat = {} + for key_name in range(len(lis)): + name = lis[key_name]['first_name'] + if name not in repeat: + repeat[name] = 1 + else: + repeat[name] += 1 + return repeat +for name,count in diction_name_count(students).items(): + print(f'{name}: {count}') +print() # Задание 2 # Дан список учеников, нужно вывести самое часто повторящееся имя @@ -26,7 +37,18 @@ {'first_name': 'Маша'}, {'first_name': 'Оля'}, ] -# ??? +repeat = diction_name_count(students) +def max_name(diction): + max_count = 0 + for name,count in diction.items(): + if count > max_count: + max_count = count + max_n = name + return max_n + + +print(f'самое частое имя среди учеников: {max_name(repeat)}') +print() # Задание 3 @@ -51,8 +73,10 @@ {'first_name': 'Саша'}, ], ] -# ??? +for classes in range(len(school_students)): + print(f'Самое частое имя в классе {classes+1}: {max_name(diction_name_count(school_students[classes]))} ') +print() # Задание 4 # Для каждого класса нужно вывести количество девочек и мальчиков в нём. @@ -72,7 +96,27 @@ 'Миша': True, 'Даша': False, } -# ??? + +for classy in range(len(school)): + clas = school[classy] + nomer_classa = clas['class'] + boys = [] + girls = [] + student = clas['students'] + for n in student: + name = n['first_name'] + if is_male[name] == True: + boys.append(name) + else: + girls.append(name) + count_boys = len(boys) + count_girls = len(girls) + print(f'Класс {nomer_classa}: девочки {count_girls}, мальчики {count_boys}') +print() + + + + # Задание 5 @@ -91,5 +135,36 @@ 'Олег': True, 'Миша': True, } -# ??? +clas_count_boys = 0 +clas_count_girls = 0 +clas_max_boys = '' +clas_max_girls = '' + +for classy in range(len(school)): + clas = school[classy] + nomer_classa = clas['class'] + boys = [] + girls = [] + student = clas['students'] + + for elem in student: + name = elem['first_name'] + + if is_male[name] == True: + boys.append(name) + else: + girls.append(name) + + count_boys = len(boys) + count_girls = len(girls) + + if count_boys > clas_count_boys: + clas_count_boys = count_boys + clas_max_boys = nomer_classa + if count_girls > clas_count_girls: + clas_count_girls = count_girls + clas_max_girls = nomer_classa +print(f'Больше всего мальчиков в классе {clas_max_boys}') +print(f'Больше всего девочек в классе {clas_max_girls}') +print() From a41093ba9c8ab6cefe834d96247ddeec9fe457a0 Mon Sep 17 00:00:00 2001 From: Stas Petrov Date: Mon, 20 Feb 2023 10:02:04 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B8=D0=BB=20for?= =?UTF-8?q?=5Fdict=5Fchallenges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 24951b39..5ddaabae 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Python: Module", "type": "python", "request": "launch", - "module": "for_challenges", + "module": "for_dict_challenges", "justMyCode": true, "console": "internalConsole" } From d0bc7c183a2d788353031a5b666dcede744994e3 Mon Sep 17 00:00:00 2001 From: Stas Petrov Date: Mon, 20 Feb 2023 10:32:35 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20string=5Fchallenges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- string_challenges.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/string_challenges.py b/string_challenges.py index 856add2d..4750b51c 100644 --- a/string_challenges.py +++ b/string_challenges.py @@ -1,28 +1,46 @@ # Вывести последнюю букву в слове word = 'Архангельск' -# ??? +print(word[-1]) +print() # Вывести количество букв "а" в слове word = 'Архангельск' -# ??? +print(len(word)) +print() # Вывести количество гласных букв в слове word = 'Архангельск' -# ??? +vowels ='аоуыэеёиюя' +vowels_list = [] +for letter in word.lower(): + if letter in vowels: + vowels_list.append(letter) +print(len(vowels_list)) +print() # Вывести количество слов в предложении sentence = 'Мы приехали в гости' -# ??? - +sentence = sentence.split() +print(len(sentence)) +print() # Вывести первую букву каждого слова на отдельной строке sentence = 'Мы приехали в гости' -# ??? +sentence = sentence.split() +for word in sentence: + print(word) +print() # Вывести усреднённую длину слова в предложении sentence = 'Мы приехали в гости' -# ??? \ No newline at end of file +sentence = sentence.split() +sum = 0 +for word in sentence: + sum += len(word) +average = sum//len(sentence) +print(average) +print()