-4

There are no syntax error or compilation error found. Why is not this program executing? I am not able to catch why is this program not running if has no compilation errors. What could logically go wrong in this below code? What can I add into this code to make it run and interact?

def main():
    print "Checking platform...\r\r\r"
    platform = systemdetails()

def systemdetails():
    print "Hello! Welcome to the auto-commander"
    print "Please enter the platform specific number to automate."
    platforminput = integer(input ("1. Cisco       2. Linux/Unix     3. Juniper       4. VMware vSphere/NSX \n:"))
    if platforminput ==1:
        platform='cisco_ios'
    elif platforminput ==2:
        platform='linux'
    elif platforminput ==3:
        platform='juniper'
    elif platforminput ==4:
        platform='vmware'
    else:
        print "Commander has to repeat the question...\n\n"
        systemdetails()
    return platform
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
  • When you recurse because the user entered an incorrect response, you don't return the value of that call. It should be `return systemdetails()`. But it's better to use a loop rather than recursion for this. – Barmar Oct 14 '16 at 01:29
  • 5
    You have no call to `main()` – Barmar Oct 14 '16 at 01:30
  • http://stackoverflow.com/questions/17257631/the-main-function-appears-to-not-work – TigerhawkT3 Oct 14 '16 at 01:42
  • 1
    @techydesigner Please keep in mind the OP does not have to accept any answer: http://meta.stackoverflow.com/questions/256479/should-i-accept-a-useful-answer-even-though-it-doesnt-answer-the-question – Christian Dean Oct 14 '16 at 02:07

2 Answers2

5

You'll need to call your main function. A minimal example that still reproduces your problem is

def main():
    print "Hello World!"

To get this to work, you need to call your main

def main():
    print "Hello World!"

main()

Generally you only want to call your main if you are not being imported, which can be done like so

def main():
    print "Hello World!"

if __name__ == '__main__':
    main()
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
3

You need to call your main() function.

Either like this:

main()

Or like this:

if __name__ == "__main__":
    main()

In the second example, main() will only be called if you run the program directly rather than importing the module and running functions individually. This way, you can import the module's functions to use separately without main() running when importing.

techydesigner
  • 1,681
  • 2
  • 19
  • 28