-
Notifications
You must be signed in to change notification settings - Fork 260
задание по for готово #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
# Необходимо вывести имена всех учеников из списка с новой строки | ||
|
||
names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
# ??? | ||
|
||
for name in names: | ||
print(name) | ||
|
||
# Задание 2 | ||
# Необходимо вывести имена всех учеников из списка, рядом с именем показать количество букв в нём | ||
|
@@ -12,7 +12,8 @@ | |
# Петя: 4 | ||
|
||
names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
# ??? | ||
for name in names: | ||
print(f'{name}: {len(name)}') | ||
|
||
|
||
# Задание 3 | ||
|
@@ -25,8 +26,12 @@ | |
'Маша': False, | ||
} | ||
names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
# ??? | ||
|
||
for name in names: | ||
if is_male[name] is False: | ||
print(f'{name}: Ж') | ||
else: | ||
print(f'{name}: М') | ||
|
||
# Задание 4 | ||
# Даны группу учеников. Нужно вывести количество групп и для каждой группы – количество учеников в ней | ||
|
@@ -40,18 +45,25 @@ | |
['Вася', 'Маша', 'Саша', 'Женя'], | ||
['Оля', 'Петя', 'Гриша'], | ||
] | ||
# ??? | ||
print(f'Всего {len(groups)} группы') | ||
for index, name in enumerate(groups, start=1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
print(f'Группа {index}: {len(name)} ученика') | ||
|
||
|
||
|
||
# Задание 5 | ||
# Для каждой пары учеников нужно с новой строки перечислить учеников, которые в неё входят | ||
# Пример вывода: | ||
# Группа 1: Вася, Маша | ||
#Группа 1: Вася, Маша | ||
# Группа 2: Оля, Петя, Гриша | ||
|
||
groups = [ | ||
['Вася', 'Маша'], | ||
['Оля', 'Петя', 'Гриша'], | ||
['Вася', 'Маша', 'Саша', 'Женя'], | ||
] | ||
# ??? | ||
|
||
|
||
for index, names in enumerate(groups, start=1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
names = ', '.join(names) | ||
print(f'Группа {index}: {names}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
# Вывести последнюю букву в слове | ||
word = 'Архангельск' | ||
# ??? | ||
print(word[-1]) | ||
|
||
|
||
# Вывести количество букв "а" в слове | ||
word = 'Архангельск' | ||
# ??? | ||
print(word.lower().count('а')) | ||
|
||
|
||
# Вывести количество гласных букв в слове | ||
word = 'Архангельск' | ||
# ??? | ||
count = 0 | ||
for i in word.lower(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if i in 'ауоыяюёие': | ||
count += 1 | ||
print(count) | ||
|
||
|
||
# Вывести количество слов в предложении | ||
sentence = 'Мы приехали в гости' | ||
# ??? | ||
print(len(sentence.split())) | ||
|
||
|
||
# Вывести первую букву каждого слова на отдельной строке | ||
sentence = 'Мы приехали в гости' | ||
# ??? | ||
for i in sentence.split(): | ||
print(i[0]) | ||
|
||
|
||
# Вывести усреднённую длину слова в предложении | ||
sentence = 'Мы приехали в гости' | ||
# ??? | ||
count_word = len(sentence.split()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. так тоже можно |
||
count_letter = 0 | ||
for i in sentence: | ||
if i.isalpha(): | ||
count_letter += 1 | ||
print(count_letter / count_word) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
как бы ты разрулил случай, когда имя отсутствует в is_male ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно циклом for вытащить key, value. Так for key, value in is_male, а потом так же через if. Правильно понял вопрос?