Python, connect menu to functions
<p>I have got a menu and a couple of functions to continue working with.My task is to add more functions. The menu code right now, looks like this.</p>

<pre><code>def menu():

"""
Display the menu with the options that The Goddamn Batman can do.
"""
print(chr(27) + "[2J" + chr(27) + "[;H")
print(meImage())
print("Hi, I'm The Goddamn Batman. There is nothing I can't do. What can I do you for?")
print("1) Present yourself to The Goddamn Batman.")
print("2) Tell me your age. I'm going to show you a neat trick.")
print("q) Quit.")
</code></pre>

<p>The problem is print2. I get the alternative to show up in Cygwin but I when I press "2", I get an error. The function (not complete) looks like this:</p>

<pre><code>def Age():
"""
Ask the user's age and calculate for how many seconds the user has lived
"""

age = input("How old are you? ")
    if choice == int:
        print ("Ah, %s, that is old." % age)
    result = (input * (int)31 556 926)
    return result
    print("You know what? Your age actually makes ",result, "seconds.")

    else:
        print("That is not a valid choice. Please write a number.")
</code></pre>

<p>The previous functions, print 1 (name) and print q (the quit everything one), works fine. For example, print 1 looks like this:</p>

<pre><code>def myNameIs():
    """
    Read the users name and say hello to The Goddamn Batman.
    """
    name = input("What is your name? ")
    print("\nThe Goddamn Batman says:\n")
    print("Hello %s - you're something special." % name)
    print("What can I do for you?")
</code></pre>

<p>Why won't the print 2 (age) respond? The other ones work fine but I just can't add more functions and get them to work. Hopefully this helps other people to learn how to properly connect functions to a menu. I'm just stuck.</p>

<p>So, to clarify, my problem is that the function <code>def myNameIs():</code> responds as a menu option in Cygwin. The function <code>def Age():</code> doesn't. I don't know why.</p>

<p>Thanks in advance, I'm very grateful for any help you can provide. </p>

<p>EDIT:</p>

<p>Ok, after request. This is ALL the code there is. I'm very sorry for not providing just a fiddle but I don't know any fiddles I can use for python. I only find jsfiddle and it doesn't seem to have anything meant for python in it. </p>

<pre><code>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Marvin with a simple menu to start up with.
Marvin doesnt do anything, just presents a menu with some choices.
You should add functinoality to Marvin.

"""


def meImage():
    """
    Store my ascii image in a separat variabel as a raw string
    """
    return r"""
       _==/          i     i          \==_
     /XX/            |\___/|            \XX\
   /XXXX\            |XXXXX|            /XXXX\
  |XXXXXX\_         _XXXXXXX_         _/XXXXXX|
 XXXXXXXXXXXxxxxxxxXXXXXXXXXXXxxxxxxxXXXXXXXXXXX
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
 XXXXXX/^^^^"\XXXXXXXXXXXXXXXXXXXXX/^^^^^\XXXXXX
  |XXX|       \XXX/^^\XXXXX/^^\XXX/       |XXX|
    \XX\       \X/    \XXX/    \X/       /XX/
       "\       "      \X/      "      /"
    """


def menu():
    """
    Display the menu with the options that The Goddamn Batman can do.
    """
    print(chr(27) + "[2J" + chr(27) + "[;H")
    print(meImage())
    print("Hi, I'm The Goddamn Batman. There is nothing I can't do. What can I do for you?")
    print("1) Present yourself to The Goddamn Batman.")
    print("2) Tell me your age. I'm going to show you a neat trick.")
    print("q) Quit.")


def myNameIs():
    """
    Read the users name and say hello to The Goddamn Batman.
    """
    name = input("What is your name? ")
    print("\nThe Goddamn Batman says:\n")
    print("Hello %s - you're something special." % name)
    print("What can I do for you?")

def Age():
    """
    Ask the user's age and calculate for how many seconds the user has lived
    """

    age = input("How old are you? ")
        if choice == int:
            print ("Ah, %s, that is old." % age)
        result = (input * (int)31 556 926)
        return result
        print("You know what? Your age actually makes ",result, "seconds.")

        else:
            print("That is not a valid choice. Please write a number.")





def main():
    """
    This is the main method, I call it main by convention.
    Its an eternal loop, until q is pressed.
    It should check the choice done by the user and call a appropriate
    function.
    """
    while True:
        menu()
        choice = input("--&gt; ")

        if choice == "q":
            print("Bye, bye - and welcome back anytime!")
            return

        elif choice == "1":
            myNameIs()

        else:
            print("That is not a valid choice. You can only choose from the menu.")

        input("\nPress enter to continue...")



if __name__ == "__main__":
    main()
</code></pre>

<p>You are converting years to seconds?</p>

<p>1) In python <code>int()</code> is a function that takes a parameter, it doesn't cast values like <code>(int)31 556 926</code><br>
2) integer values don't have spaces in them<br>
3) You can't put code after a <code>return</code> statement and expect it to run<br>
4) <code>choice</code> is not probably not accessible in the <code>Age</code> function. You could add it as a parameter<br>
5) Check for <code>int</code> with <code>isinstance(choice, int)</code> instead of <code>==</code>, because you want to check for the <em>type</em> of the variable, not against the <code>int</code> class itself. </p>

<pre><code>def Age():
    """
    Ask the user's age and calculate for how many seconds the user has lived
    """

    age = input("How old are you? ")
    print("Ah, %s, that is old." % age)
    result = int(input) * 31556926  # Fixed this line
    print("You know what? Your age actually makes ",result, "seconds.")
    return result   # Moved this line down
</code></pre>

<p>Regarding your menu, you never executed your functions, or prompted for <code>input</code>, but here's a trick you can do </p>

<pre><code>menu_funcs = {'1': myNameIs, '2': Age} # map the options to functions
while True:
    menu()
    choice = input("Enter an option: ")
    if choice == 'q':
        return # exit
    if choice in menu_funcs:
       menu_funcs[val]() # call the function
    else:
       print("That is not a valid choice. You can only choose from the menu.")
</code></pre>

python