1
I am trying to create a variable input function in a list that only allows entering terms not already contained in the list.
I’m having trouble finding a logical solution to this, I can’t use break
to stop the loop. I’m not taking identation errors, I’m stuck in the loop. Any path suggestions for solving the problem?
lista = []
def preencheLista(lista,taml):
for i in range(taml):
duplicidade = True
while duplicidade:
c=float(input("Entre com o termo\n"))
lista.append(c)
for i in range(len(lista)):
if c == lista[i]:
duplicidade = True
else:
duplicidade = False
if duplicidade:
print ("Valor ja existente, digite um novo valor")
else:
lista.append(c)
print (lista)
#print ("Valor ja existente, digite um novo valor")
if __name__ == '__main__':
preencheLista(lista, 10)
I applied code formatting to your question via button
{}
editor. Confirm that the code is as it was supposed to be, because the last line does not seem to respect the indentation that is behind– Isac