A
A
ARM9662021-08-08 16:31:32
Python
ARM966, 2021-08-08 16:31:32

Where is the error in the program?

The program should accept the number of names as input, the names themselves and display the names that match the rule, but only one name is accepted as input
Code:

def make_list(number):
    names = []
    for item in range(number):
        names.append(input('Введите имя с заглавной буквы'))
        return (names)

number = int(input('Сколько имен надо ввести?'))
names = make_list(number)

for name in names:
    if name[0] == 'А':
        print('Имя', name, 'Начинается с буквы А')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-08-08
@ARM966

The most interesting thing is that the code works fine if it is formatted of course.

spoiler
610fdf5a53083690110239.png

def get_names(num_items):
    name_list = list()
    for item in range(num_items):
        name_list.append(input('Введите имя с заглавной буквы'))
    return name_list


def get_quantity():
    return int(input('Сколько имен надо ввести?'))


if __name__ == '__main__':
    for name in get_names(get_quantity()):
        if name.startswith('А'):
            print('Имя', name, 'Начинается с буквы А')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question