[Tutor] input problem
christopher.henk at allisontransmission.com
christopher.henk at allisontransmission.com
Mon Sep 13 23:14:29 CEST 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100913/f3b0ffa3/attachment.html>
More information about the Tutor
mailing list