Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (anonymous):

Quick question regarding a Boolean operation: If I want to establish the condition that R!= #1 or #2 or #3...etc. What would be the syntax for that? I tried to do R!= (a or b or c or d) but seems like that's completely wrong... Could somebody please help me? Thank you!

OpenStudy (anonymous):

not sure what you mean by "establish the condition" ... maybe assert? and it's just style, but R! is a horrible name for anything, lose the punctuation if you are checking a condition, (a or b or c or d) is perfectly valid but if you don't like that, and you have sets to play, try R in [a,b,c,d]

OpenStudy (anonymous):

Hi philips13: Thanks for responding. What I meant is that I want to write a code that says 'R does not equal to a or b or c or d'. So would "R != a or b or c or d" work?

OpenStudy (anonymous):

Yes, but be careful and check the truth table. Do you want to make sure they are all false? If so, that's it. and another style point: If this check is only used once, there is no need to set a variable, and it usually makes it a lot more readable and easier to maintain. while not (a or b or c or d) ... if not (a or b or c or d) ... return not (a or b or c or d) ...

OpenStudy (anonymous):

not in is a good idiom http://dpaste.com/729349/

OpenStudy (anonymous):

yes, I forgot this was Python, tried to stay generic

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!