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
27 changes: 22 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 range(len(names)):
print(names[i])


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

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


# Задание 3
Expand All @@ -25,7 +27,11 @@
'Маша': False,
}
names = ['Оля', 'Петя', 'Вася', 'Маша']
# ???
for items in is_male:
if is_male.get(items) == True:
print(f"{items} пол мужской")
else:
print(f"{items} пол женский")


# Задание 4
Expand All @@ -40,7 +46,16 @@
['Вася', 'Маша', 'Саша', 'Женя'],
['Оля', 'Петя', 'Гриша'],
]
# ???
print(f"Всего {len(groups)} группы.")

for group in groups:
print(f"Группа {len(groups)}: {len(group)} ученика.") # Вариант когда неправильно считает номер группы.
for i in range(len(groups)):
print(f"Гпуппа {i+1}: {len(groups)} ученика.") # Вариант когда неправильно считает количество человек в группе.
# Как объединить чтобы все заработало?





# Задание 5
Expand All @@ -54,4 +69,6 @@
['Оля', 'Петя', 'Гриша'],
['Вася', 'Маша', 'Саша', 'Женя'],
]
# ???
for i in range(len(groups)):
print(f"Группа {i+1}: {groups[i]}") # Работает, но как при выводе убрать знаки "[" и "]" ?

74 changes: 68 additions & 6 deletions for_dict_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
{'first_name': 'Маша'},
{'first_name': 'Петя'},
]
# ???

names = dict()
for student in students:
if student['first_name'] not in names.keys():
names[student['first_name']] = 1
else:
names[student['first_name']] += 1
for name, count in names.items():
print(f'{name}: {count}')


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

names = [s["first_name"] for s in students]
names_and_count = {name: names.count(name) for name in names}
max_count = max(names_and_count.values())

for name, count in names_and_count.items():
if count == max_count:
print(name)



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

from collections import Counter

cl = 1
for item in school_students:
temp = [i['first_name'] for i in item]
c = Counter(temp)
print(f'Самое частое имя в классе {cl}: {c.most_common()[0][0]}')
cl += 1


# Задание 4
Expand All @@ -66,14 +90,26 @@
{'class': '2б', 'students': [{'first_name': 'Даша'}, {'first_name': 'Олег'}, {'first_name': 'Маша'}]},
]
is_male = {
'Олег': True,
'Маша': False,
'Оля': False,
'Олег': True,
'Миша': True,
'Даша': False,
}
# ???

for clas in school:
boys_count = 0
girl_count = 0
for student in clas['students']:
for name in student.values():
if is_male[name]:
boys_count += 1
else:
girl_count += 1

print("Класс {}: девочки {}, мальчики {} ".format(clas["class"],
girl_count,
boys_count))

# Задание 5
# По информации о учениках разных классов нужно найти класс, в котором больше всего девочек и больше всего мальчиков
Expand All @@ -91,5 +127,31 @@
'Олег': True,
'Миша': True,
}
# ???

clases = {}
for clas in school:
clases[clas["class"]] = {"boys_count": 0, "girls_count": 0}
boys_count = 0
girl_count = 0
for student in clas['students']:
for name in student.values():
if is_male[name]:
clases[clas["class"]]["boys_count"] += 1
else:
clases[clas["class"]]["girls_count"] += 1
clas_with_max_girl = ''
max_boys = 0
max_girls = 0
clas_with_max_boy = ''
for clas in clases.keys():
if max_boys < clases[clas]['boys_count']:
max_boys = clases[clas]['boys_count']
clas_with_max_boy = clas
if max_girls < clases[clas]['girls_count']:
max_girls = clases[clas]['girls_count']
clas_with_max_girl = clas
print(f"Больше всего мальчиков в классе {clas_with_max_boy}")
print(f"Больше всего девочек в классе {clas_with_max_girl}")



29 changes: 23 additions & 6 deletions string_challenges.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
# Вывести последнюю букву в слове
word = 'Архангельск'
# ???
print(word[-1])


# Вывести количество букв "а" в слове
word = 'Архангельск'
# ???
word = word.lower()
print(word.count('а'))


# Вывести количество гласных букв в слове
word = 'Архангельск'
# ???
word = word.lower()
def countVowels(word):
vowels = ['а','е', 'о', 'и', 'ы', 'у', 'э']
total = 0
for s in word:
if s in vowels:
total += 1
return total

print(countVowels(word))


# Вывести количество слов в предложении
sentence = 'Мы приехали в гости'
# ???
print(len(sentence.split()))


# Вывести первую букву каждого слова на отдельной строке
sentence = 'Мы приехали в гости'
# ???
letter = sentence.split()

print(letter[0][0])
print(letter[1][0])
print(letter[2])
print(letter[3][0])




# Вывести усреднённую длину слова в предложении
sentence = 'Мы приехали в гости'
# ???
print(len(letter[0]+letter[1]+letter[2]+letter[3])//len(letter))