Skip to content
Open
Changes from 1 commit
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: 20 additions & 6 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] == False:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

True, False, None в питоне являются синглтонами, поэтому сравнение с ними обычно делают через is вместо ==
if is_male[name] is False

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

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

Choose a reason for hiding this comment

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

рабочее решение, но советую посмотреть на enumerate

for number_group, number_persons in enumerate(groups, start=1):
    ...

print(f'Группа {number_group}: {len(number_persons)} ученика')
number_group += 1



# Задание 5
Expand All @@ -54,4 +64,8 @@
['Оля', 'Петя', 'Гриша'],
['Вася', 'Маша', 'Саша', 'Женя'],
]
# ???
number_group = 1
for names in groups:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

тоже через enumerate

names_str = ', '.join(names)
print(f'Группа {number_group}: {names_str}')
number_group += 1