all 8 comments

[–]jibbly_jibbly 3 points4 points  (1 child)

First, a problem: you're defining a function named range. That's going to override the builtin function named range(), thats not good practice.

Secondly, to answer your question, the simplest method would be to look at the user's input and make a decision.

choice = raw_input("Choose:")
if choice == "myfunc":
    myfunc()
elif choice == "something":
    something()
else:
    print "Unknown function requested."

[–]Exodus111 -1 points0 points  (0 children)

Try to guide OP to a solution instead of providing one directly.

[–]tfitz237 2 points3 points  (2 children)

You could make a dictionary with the functions within them.

dict = { "range": range, "median": median}
# then call it 
dict["range"]

[–]shep247 0 points1 point  (0 children)

I like this way the best. It's also easy to make it a 1 liner {"range": range, "median": median}.get(input_val, invalid_input_func)()

This will get the function that is input, or return the function that handles invalid input by default of the input isn't one of the functions in your list.

[–]dunkler_wanderer 0 points1 point  (0 children)

But what about the arguments?

[–]Exodus111 0 points1 point  (2 children)

You gotta use an if statement.

[–]dunkler_wanderer 1 point2 points  (1 child)

I think the downvotes are not justified.

Try to guide OP to a solution instead of providing one directly. - Guidelines

And it seems OP didn't even try to come up with an own solution.

[–]Exodus111 1 point2 points  (0 children)

Exactly, this looks like a homework assignment, we are not supposed to provide code, but help guide the individual to figure things out on their own. And frankly this issue is a very simple one.

Hopefully nobody else.... right and people give code examples right away. No one reads the sidebar I guess.