0

Ok, so I'm fairly new to python, and for some reason, I seem to be messing something up here. Any help? Whenever I run the program, it seems to default to the first function.

import time
main_menu = 5

def option1():
    print time.localtime()
    main_menu = 5
    main()
def option2():
    print 'You selected Option 2'
    main_menu = 5
    main()
def option3():
    print 'You selected Option 3'
    main_menu = 5
    main()

def main():
    main_menu = 5
    while main_menu==5:
        print '[1] Select option 1'
        print '[2] Select option 2'
        print '[3] Select option 3'
        mainInput = raw_input("Welcome! Type a selection\n> ")
        if mainInput == "1" or "one":
            main_menu = 6
            option1()
        if mainInput == "2" or "two":
            main_menu = 6
            option2()
        if mainInput == "3" or "three":
            main_menu = 6
            option3()

main()
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
Eric Wiles
  • 245
  • 1
  • 3
  • 5
  • What you want is `if mainInput == "1" or mainInput == "one": main_menu = 6 ....` – greg_data Dec 09 '15 at 14:53
  • 1
    Short answer: change your tests to `if mainInput == "1" or mainInput == "one":` – Antwane Dec 09 '15 at 14:55
  • To be clear, `mainInput == "1" or "one"` is parsed as `(mainInput == "1") or "one"`. Since `bool("one")` is `True`, the latter is `? or True` which is always `True` -- as you discovered. – Terry Jan Reedy Dec 09 '15 at 17:43

0 Answers0