samedi 4 novembre 2017

Menu navigation with if and else in Python

This is my little menu navigation with if and else statements:

def navigation():


    navigation_eingabe = int(input())


    if navigation_eingabe == 1:
        met1()
    if navigation_eingabe == 2:
        pass
    if navigation_eingabe == 3:
        pass
    if navigation_eingabe == 4:
        pass
    if navigation_eingabe == 5:
        pass
    if navigation_eingabe == 6:
        pass
    else:
        print("Pls give only Integer numbers")


def met1():
    print("method1")
    met2()

def met2():
    print("method2")


navigation()

Its not working correctly, after I give the Input as 1, the code goes to met1, then to meth2 and then to the else statement. I dont know why?

And then I program this alternativ code with a example:

x = int(input())

def navigation ():
    if x == 1:
        print("1")
        xx1()
    if x == 2:
        print("2")
        xx2()
    else:
        print("else statement")


def xx1():
    print("this is met1")

def xx2():
    print("this is met2")


navigation()

But in this code, the statement is working correctly, why not in the first code? Is this a problem with functional programming logic, or with the statement structury? but I cant see the difference of this two codes.

Thank you!

Aucun commentaire:

Enregistrer un commentaire