@hellen7261
учитель информатики в школе

Не могу найти ошибку в программе, хотя она работает?

def print_friends_count(friends_count, name=''):  # добавьте новый аргумент
    if friends_count == 1:
        text = '1 друг'
    #elif 2 <= friends_count <= 4:
       # text = str(friends_count) + ' друга'
    elif friends_count >= 2:
        text = str(friends_count) + ' друзей'
    if name != '':
        print(name + ', у тебя ' + text)
    else:
        print('У тебя ' + str(friends_count) + ' друзей')
  
 # дальше код не меняйте
print_friends_count(3, 'Артём')
print_friends_count(friends_count=7, name='Марина')
print_friends_count(6)
print_friends_count(4, name='Настя')
  • Вопрос задан
  • 681 просмотр
Пригласить эксперта
Ответы на вопрос 3
def print_friends_count(friends_count, name=None):
    count = str(friends_count if friends_count > 0 else '')

    if friends_count == 1:
        text = ' друг'
    elif 2 <= friends_count <= 4:
        text = ' друга'
    elif friends_count >= 5:
        text = ' друзей'
    else:
        text = 'нет друзей'

    if name:
        print(name + ', у тебя ' + count + text)
    else:
        print('У тебя ' + count + text)
Ответ написан
verbalistus
@verbalistus
Получилось так:

def print_friends_count(friends_count, name =''):  # добавьте новый аргумент
    if friends_count == 1:
        text = '1 друг'
    elif 2 <= friends_count <= 4:
        text = str(friends_count) + ' друга'
    elif friends_count >= 5:
        text = str(friends_count) + ' друзей'
    if name !='':
        print(name +', у тебя '+text)
    else:
        print('У тебя ' + name + text)
# дальше код не меняйте
print_friends_count(3, 'Артём')
print_friends_count(friends_count=7, name='Марина')
print_friends_count(6)
print_friends_count(4, name='Настя')
Ответ написан
Комментировать
@B37566004
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы