Notes

Boolean

  • Represents logical propositions
  • Either true or false, such as testing for two numbers being equal
  • Represented with variables

Logical Operators

  • Not displays the opposite
  • And is used for two conditions together
  • Or is when using the function to see if one condition is met

Nested Conditional

  • Output changes based on what is written
  • Nested conditional statements have a coditional statement inside of another conditional statement.
  • TCalled nested conditional because they are nested together,
  • Can be used for varying "else if statement"

Hacks

3.5

  • Explain in your own words what each logical operator does
    • Not statement will display based on if the result is the opposite of the data.
    • And Statement will display only if both of the conditions within the code are met.
    • Or statements will display if at least one of the conditionals within the code are met.
  • Code your own scenario that makes sense for each logical operator
isJuly = False
if not isJuly:
    print("It is not july")
It is not july
grade = 95
if grade < 100 and grade >= 90:
    print("You have an A")
You have an A
window = "open"
door = "closed"
if window == "open" or door == "open":
    print("there is a way out")
else:
    print("There is not a way out")
there is a way out

3.6

  • Selection: Code that is only executed if true or if false.
  • Algorithm: Code that has instructions in which its goal is to complete something.
  • Conditional Statement: Code that runs depending on if the result is true or false.
  • For the first hack, pretend you are a school's test grader. Create an array with integers, each integer representing one score from a student's taken tests. If the average of the student's test scores are at least 75 percent, then display that the student is elligible for credit, and if not, display that the student must retake the tests over break.
grades = [78, 85, 56, 99, 96]
average = sum(grade) / len(grade)
if (average > 75):
    print("eligible for credit")
else:
    print("not eligible for credit")
  • The second hack is more number-oriented. Create an algorithm that calculates the sum of two numbers, then determines whether the sum is greater than or less than 100.
grades = [78, 33]
scoreSum = sum(grades)
if scoreSum > 100:
    print("greater than 100")

Binary Conditional Logic