''' Purpose: introduce the logical operators ''' print() print( '##### Logical values (bool)' ) print() print( True ) print( False ) a = True b = False print(); input( 'Enter when ready: ' ); print() print( '##### Logical and' ) print() # GENERAL RULE: # When it comes to and, the minute you have at least one False, the whole thing is False. # With and, it is only true when both values are True! and1 = ( a and a ) # True and True is True and2 = ( a and b ) # True and False is False and3 = ( b and a ) # False and True is False and4 = ( b and b ) # False and False is False print( a, 'and', a, '=', and1 ) print( a, 'and', b, '=', and2 ) print( b, 'and', a, '=', and3 ) print( b, 'and', b, '=', and4 ) print(); input( 'Enter when ready: ' ); print() print() print( '##### Logical or' ) print() # GENERAL RULE: # When it comes to and, if you have at least one True, the whole thing is True. # If you have both be False, then it is False. Because both values being false means that neither value is True so the output cannot be True! or1 = ( a or a ) # True or True is True or2 = ( a or b ) # True of False is True or3 = ( b or a ) # False or True is True or4 = ( b or b ) # False and False is False print( a, 'or', a, '=', or1 ) print( a, 'or', b, '=', or2 ) print( b, 'or', a, '=', or3 ) print( b, 'or', b, '=', or4 ) print(); input( 'Enter when ready: ' ); print() print( '##### Logical negation' ) print() # Not something will be the opposite of whatever the boolean is negate1 = ( not a ) # Not True is False negate2 = ( not b ) # Not False is True print( 'not', a, '=', negate1 ) print( 'not', b, '=', negate2 ) print()