''' Purpose: introduce relational operators ''' # get two numbers from user print() a = input( 'Enter string: ' ) b = input( 'Enter string: ' ) # convert inputs to integer # # a = int( sa ) # b = int( sb ) # compare and record results # This is an introduction to relational operators. # Logical expressions like a < b evaluate to Python boolean values True or False. # In Python, there is another type called boolean that is only two values (True/False) # We can use these logical expressions to test if something is true or false # So an example is if a = 2 and b = 3, a < b is 2 < 3 and that evaluates to True! So # b1 is set to True. b1 = ( a < b ) # < is less than b2 = ( a > b ) # > is greater than b3 = ( a <= b ) # <= is less than or equal to b4 = ( a >= b ) # >= is greater than or equal to b5 = ( a == b ) # == is equals b6 = ( a != b ) # != is not equals # display results print( a, '< ', b, ':', b1 ) print( a, '> ', b, ':', b2 ) print() print( a, '<=', b, ':', b3 ) print( a, '>=', b, ':', b4 ) print() print( a, '==', b, ':', b5 ) print( a, '!=', b, ':', b6 ) print() # Comparing Strings: # Strings are compared character by character. # a < b < ... z # ab < ac # The reason why is because it will compare the first two characters ('a' from string 1 and # 'a' from string 2 and see they're the same and then compare # the second two 'b' and 'c' and say "oh! b is before c and b < c" so that entire string # is less than the second string. # Likewise # 'aac' < 'aad' # '153' < '17' # strings - since the '1's are the same and when it moves to the second characters '5' < '7' # 153 > 17 # Numbers