Skip to content

задание по 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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
26 changes: 19 additions & 7 deletions for_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Необходимо вывести имена всех учеников из списка с новой строки

names = ['Оля', 'Петя', 'Вася', 'Маша']
# ???

for name in names:
print(name)

# Задание 2
# Необходимо вывести имена всех учеников из списка, рядом с именем показать количество букв в нём
Expand All @@ -12,7 +12,8 @@
# Петя: 4

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


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

for name in names:
if is_male[name] is False:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как бы ты разрулил случай, когда имя отсутствует в is_male ?

Copy link
Author

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. Правильно понял вопрос?

print(f'{name}: Ж')
else:
print(f'{name}: М')

# Задание 4
# Даны группу учеников. Нужно вывести количество групп и для каждой группы – количество учеников в ней
Expand All @@ -40,18 +45,25 @@
['Вася', 'Маша', 'Саша', 'Женя'],
['Оля', 'Петя', 'Гриша'],
]
# ???
print(f'Всего {len(groups)} группы')
for index, name in enumerate(groups, start=1):

Choose a reason for hiding this comment

The 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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

names = ', '.join(names)
print(f'Группа {index}: {names}')
22 changes: 16 additions & 6 deletions string_challenges.py
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():

Choose a reason for hiding this comment

The 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())

Choose a reason for hiding this comment

The 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy