I was trying to come up with a dictionary of functions, but get it not to work.
bumsfeld 413 Nearly a Posting Virtuoso
Recommended Answers
Jump to PostSorry, mindreading is not my métier. Please gives us an example of your code and the error message you get.
Jump to PostG-Do did give you the hint, don't call the functions from the dictionary, just reference them. I took the liberty to play with your code a little ...
def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a …
Jump to PostThat's where the calc() function would come in handy, change it to ...
def calc(math_op, a, b): if math_op in mathD: return mathD[math_op](a, b) else: print "'%s' not recognized" % math_op
All 9 Replies
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
G-Do 19 Junior Poster
bumsfeld 413 Nearly a Posting Virtuoso
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
bumsfeld 413 Nearly a Posting Virtuoso
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
Kyss 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Kyss 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.