The program skips the IF and goes straight to the ELSE [closed]

2

I'm practicing the exceptions in python and I have a problem, the exceptions are captured well but then the program does not work correctly.

#Utilizamos este metedo para importar las funciones del archivo
from Funciones import llegadaCamion,nuevoCamion,procesarEnvios,menu,visualizarCamiones,visualizarEnvios,visualizarCiudades

while True:
    # Mostramos el menu
    menu()
        # solicituamos una opción al usuario
    while True:
            try:
                opcionMenu = (int(input("inserta un numero valor >> ")))
                break
            except ValueError:
                print("El valor introducido no es correcto vuelve a intentarlo")

    if opcionMenu=="1":
        print ("")
        nuevoCamion()                      
    elif opcionMenu=="2":
        print ("")
        llegadaCamion()
    elif opcionMenu=="3":
        print ("")
        procesarEnvios()
    elif opcionMenu=="4":
        print("")
        visualizarEnvios()
    elif opcionMenu=="5":
        print("")
        visualizarCamiones()
    elif opcionMenu=="6":
        print("")
        visualizarCiudades()
    elif opcionMenu=="7":
        print ("")
        break
    else:
        input("No has pulsado ninguna opción correcta...\npulsa una tecla para continuar")

The fact is that when entering the data well, for example, the 1 does not enter the if it goes directly to the else, that happens in all the options, I do not understand why it does not enter the if.

    
asked by David 16.05.2018 в 13:42
source

1 answer

4

The error probably lies in the type of data you have in your if condition. By doing opcionMenu == "1" you are surely trying to compare an integer with a string in this way Int == String and therefore the condition is not met.

Use opcionMenu == 1 to compare the number as a number and not as a text string

    
answered by 16.05.2018 / 13:51
source