I have something like a switch, which will make an option call a function eg
# ... capture option op = getOption () # .. Capture Metric MT = Mammatic () DIF Zipcode (): Print "You have typed zero. \ N" def desc ( ): Print "n is an ideal class \ n" def address (): print "n is a number \ n" #call desired option option = {0: zipcode, 1: code, 2: character, 3: address} I am trying to call a parameter ( mt ) in my option dict in the options [op] () , But I'm not able to do this .
If the session received is 1 and MT is FU, then how will MT call the correct function (PINCODE) by passing it as parameter?
Model: option [session] (MT) and define a parameter in the function?
Thanks
Your code has not been properly indexed, in Python Is very important and will cause syntax errors such as.
However, the suggestions you are making are completely working.
def multiply (m, n): return n * n def add (m, n) return m, n my_math = {"+": add, "*": multiply } You can then call:
& gt; & Gt; & Gt; Print my_math ["+"] (1,2) 3> gt; & Gt; & Gt; Print my_math ["*"] (4,5) 20
No comments:
Post a Comment