Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 1st, 2012, 11:38 PM
knutrainer knutrainer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: U.S A.Z.
Posts: 24 knutrainer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
Send a message via AIM to knutrainer
'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?

Reply With Quote
  #2  
Old December 2nd, 2012, 01:01 AM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
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

Reply With Quote
  #3  
Old December 2nd, 2012, 01:13 AM
knutrainer knutrainer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: U.S A.Z.
Posts: 24 knutrainer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
Send a message via AIM to knutrainer
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > 'and' does not work as I thought

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap