0
import re

def cleanseCommand(x):
    return ''.join(re.split(r'[.;!/?,]', x))



while(True):

    temp = raw_input("Give command-").split()

    for i in range(0,len(temp)):
        temp[i]= cleanseCommand(temp[i]) 

    if(''.join(temp)=='exit'):
        sys.exit()
    if(temp[0]=="generate" or 'test' or 'randomize' or 'randomise' or 'go'):
        print 'bunnies' 

Python 2.7.5

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

2 Answers2

2

This expression is not doing what you want, because it's always true - if temp[0] evaluates to False then it's value is string 'test', which is True in boolean context:

if(temp[0]=="generate" or 'test' or 'randomize' or 'randomise' or 'go'):

What you apparently meant is something like:

if(temp[0]=="generate" or temp[0]=='test' or temp[0]=='randomize' or temp[0]=='randomise' or temp[0]=='go'):

You can also replace the above with a bit nicer:

if(temp[0] in ("generate",'test', 'randomize', 'randomise', 'go')):
piokuc
  • 25,594
  • 11
  • 72
  • 102
0

Try changing it to this...

if (temp[0]=='generate') or (temp[0] == 'test') or (temp[0] == 'randomize') or (temp[0] == 'randomise') or (temp[0] == 'go'):
    print 'bunnies' 
Adam Stark
  • 422
  • 1
  • 5
  • 12