I can not run this giving error of indexing what is wrong

Asked

Viewed 72 times

0

def main():

    q = Queue()
    i=1


    while(q.isFull()==False):
        digitado = input ("digite um numero para inserir na fila: ")
        numLido = int(digitado)
        q.enqueue(numLido)
        i+=1


    while (True):

        x = input ("Digite uma opção: ")       
        print ("1. Imprimir uma fila (sem destruí-la)")
        print ("2. Copiar uma fila para outra")
        print ("3. Verificar se duas filas são iguais")
        print ("4. Remover um elemento da fila, conservando o restante da fila.")
        print ("0. Para SAIR")

        if (x == 1):
            q.imprime()

        elif (x == 2):

        elif (x == 3):

        elif (x == 4):

        elif (x == 0):
            print ("SAIU...")
            break
        else:
            print("ERRO! ")       

if name=="main": 
    main()

1 answer

3

I don’t know where this class is coming from Queue, but if it is from Python itself, from the module queue, there are many errors in your program. But considering that it is its own implementation and that all the methods used exist, I list the errors:

  1. Your condition to perform main is wrong. Right is right:

    if __name__ == "__main__":
        main()
    
  2. It makes no sense to read the option before displaying the possibilities and if you are going to compare it with integer values, you need to convert it to integer.

    print ("1. Imprimir uma fila (sem destruí-la)")
    print ("2. Copiar uma fila para outra")
    print ("3. Verificar se duas filas são iguais")
    print ("4. Remover um elemento da fila, conservando o restante da fila.")
    print ("0. Para SAIR")
    x = int(input("Digite uma opção: "))
    
  3. Your problem of identation is in elif that do not execute any code. Python does not allow this. If you want to implement logic later, but still maintain conditions, use the directive pass.

    if (x == 1):
        q.imprime()
    
    elif (x == 2):
        pass
    
    elif (x == 3):
        pass
    
    elif (x == 4):
        pass
    
    elif (x == 0):
        print ("SAIU...")
        break
    else:
        print("ERRO! ") 
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.