Does not satisfy the condition with the value informed by the user

-1

I made this code, but it does not enter the option entered by the user (I think the options already says what he has to do).

lista = []
while True:
    print("Adicionar nome - 1")
    print("Sair - 0")
    print("Listar - 2")
    op = input()

    if op == 0:
        break
    elif op == 1:
        nome = input("Digite o nome")
        lista.append(nome)
    elif op == 2:
        j = 0
        for nomes in lista:
            print(nomes)
    
asked by anonymous 28.06.2018 / 14:35

1 answer

4

The input input() causes the user to enter a string, so when you compare op == 0 you are comparing a string with an integer. To solve this you have 2 options:

1st:

op = input()
if op == '0':
   break

2nd: Use int(input()) to receive an integer

op = int(input())
if op == 0:
   break
    
28.06.2018 / 14:41