ANKUR AGGARWAL wrote on 09/13/2010 04:45:41 PM:

> 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

You put your inputs into a list and see if "hello" is in the list.
 
    inputlist=[a,b,c,d]
    if "hello" in inputlist:
        fun()

or if you want to run fun() once for every "hello" you can then loop over 
the list.

    inputlist=[a,b,c,d]
    for inputitem in inputlist: 
        if "hello" == inputitem:
            fun()

Chris
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to