On Tue, Sep 14, 2010 at 6:45 AM, ANKUR AGGARWAL <coolankur2...@gmail.com> wrote: > Suppose i am taking input or various variables like > a=raw_input("...............") //hello > b=raw_input("................")//hi > c=raw_input("...............")//hello > d=raw_input("..........")//hello > but i want to run a common function when input is hello > so instead of > if a=="hello": > fun() > then again for b and then again for c then d and so on i have to apply the > code for the specific variable , > i want to run the function whenever in the code input is "hello" > i am wondering is there is any way like > if input=="hello": > fun() > i hope you get my point.. Help me out please > Thanks in advance
How about this design pattern: def hello(): print "Hello World!" prompt = "..." s = raw_input(prompt) while s: if s == "hello": hello() elif s == "quit": break s = raw_input(prompt) cheers James -- -- James Mills -- -- "Problems are solved by method" _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor