-1
Create a program where the user can enter several numerical values and register them in a list. If the number already exists inside, it will not be added. At the end, all unique values typed will be displayed, in ascending order.
And so far so good this was my solution:
lista= []
while True:
ad = (int(input('Digite um valor: ')))
if ad not in lista:
lista.append(ad)
print('Adicionado com sucesso!')
else:
print('Valor duplicado. Adição negada.')
ask = str(input('Deseja continuar?[S/N] ')).strip().upper()[0]
while ask not in 'SN':
if ask == 'S':
continue
elif ask == 'N':
break
elif ask != 'SN':
print('Resposta inválida, por favor escolha entre [S/N]')
while ask not in 'SN':
ask = str(input('Deseja continuar?[S/N] ')).strip().upper()[0]
print('-=' * 30)
lista.sort()
print(f'Voce digitou os números: {lista}')
When asked if I want to continue and I answer 'N' the program keeps working without giving the break
. However the same code in another colleague’s Pycharm works without any problem.
What can that be? One bug? It is possible to solve it?
ask
can only be'S'
or'N'
, but you use the conditionwhile ask not in 'SN'
. Something wrong is not right.– Woss