From what I understand you want to add names inside a list until you decide parar
. For this, you can use the following algorithm:
cont = 0
elementos = list()
while True:
cont += 1
elementos.append(input(f'Nome do {cont}º elemento: '))
resp = input('Fim [S/N]? ').upper()
while (len(resp) != 1) or (resp not in 'SN'):
print('\033[31mValor INVÁLIDO! Digite apenas "S" ou "N"!\033[m')
resp = input('Fim [S/N]? ').upper()
if resp == 'N':
print(f'\033[32mA lista formada foi: {elementos}\033[m')
break
Note that when we run the following algorithm we receive the following message: Nome do 1º elemento:
. At this point we must enter the name and press Enter
. Then we received the following message; Fim [S/N]?
. If we wish to continue just type S
and press enter
. Then the algorithm will request the next name and so on.
Now, if we want to close, just type N
and press enter
. At this time the algorithm will display the list formed by all the elements previously typed and then will terminate its execution.
I was able to solve using your solution as a basis (the problem involved more things). Thank you very much!
– oroborus_0
For nothing! Hug!
– lmonferrari