Selection Exercises

Comparison (relational and equality) Operators:
  1. With your neighbor, identify the 6 common comparison operators and explain what each one does:
    1. ==, tests for equality (Example: a*a == b*b + c*c)
Logical Operators:
  1. With your neighbor, identify the 3 logical operators and explain what each one does:
    1. and, combines two boolean expressions and results in True if and only if both of the boolean expressions are True (Example: (age >= 13) and (acceptedAgreementTerms == True))
  2. Given a variable age, write a boolean expression that evaluates to True only when age represents a teenager. (Can you come up with another way to evaluate age that meets this criterion?)
  3. What does the following evaluate to?
    hairColor == "blond" or "brown" or "red" or "black"
    
  4. Determine the correct order of precedence among the following:
    Category Operators
    addition +,-
    exponent **
    logical and
    logical or
    logical not
    multiplication *,/,//,%
    relational ==,!=,<=,>=,>,<
  5. Add as many parenthesis as possible to the the following expressions (without the order of operations):
    1. val * 3 > 10 and option == True or override == True
    2. 5 + 6 * 7 / 8 > 9 and 4 - 3 ** 2 / 10 or fee / 10 < 100
    3. fileExists == False or fileOpenedSuccessfully == True and errorReadingFile == True
  6. Draw flowcharts for the following two if-statements:
    if fellowScouter == True:
        shakeWithLeftHand()
    else:
        shakeWithRightHand()
    
    if name == "Honey":
        print("Love ya!")
    else:
        print("See ya")
    
  7. Individually, code two if-else statements and two if statements. Be sure to include the ":"(s) and to indent the code in each body. Share your examples with your neighbor.