#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0

    'and' does not work as I thought


    Code:
    space1 = 'X'
    space2 = 'O'
    space3 = 'X'
    if space1 and space2 and space3 == 'X':
    	print 'space1 and space2 and space3 all equal X'
    else: print 'space1 and space2 and space3 do not all equal X'
    I would expect this code to print that it space1 2 and 3 do not equal X. How would I make this code print space1 2 and 3 do not equal x?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    The grouping of your expression is:
    Code:
    if ((space1) and (space2) and (space3 == 'X')):
        ...
    See why it didn't work?

    Comments on this post

    • knutrainer agrees : Great way to let me see the answer instead of just telling me
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    Code:
    space1 = 'X'
    space2 = 'O'
    space3 = 'X'
    if space1 == 'X' and space2 == 'X' and space3 == 'X':
        	print 'space1 and space2 and space3 all equal X'
    else: print 'space1 and space2 and space3 do not all equal X'
    Ok this works. Thanks for putting it into perspective for me.

IMN logo majestic logo threadwatch logo seochat tools logo