What is a boolean?

-A data type with two possible values: true or false Boolean and Binary So similar yet so different.

-Boolean math and binary notation both use the same two ciphers: 1 and 0.

However, please note that Boolean quantities are restricted to a singlular bit (can only be either 1, or 0)

On the otherhand, binary numbers may be composed of many bits adding up in place-weighted form to any finite value, or size

Relational Operators in action

How could you use operators to determine if the average of 5 grades is greater than 80?

With the grades below, use a boolean expression to determine if the average grade is above an 80 and print the result (True or False)

Try it in as few steps as possible! Be creative! There are obviously TONS of different practical solution

grade1 = 90
grade2 = 65
grade3 = 60
grade4 = 75
grade5 = 95

grades = grade1 + grade2 + grade3 + grade4 + grade5 

average = grades % 5

average > 80

if average == 0:
    print("false")   
else: 
    print("true")
false

Conditionals

Focusing on Selection Selection: uses a condition that evaluates to true or false

Selection determines which part of an algorithm are executed based on a condition being true or false

Algorithm is a finite set of instructions that accomplish a specific task

Conditional Statements Also known as "if statements"

Can be seen as if statements or if blocks

Can also be seen as if else statements or if else-blocks

x = 20
y = 10
if x > y:
    print("x is greater than y")
x is greater than y
x = 20
y = 10
if x > y:
    print("x is greater than y")
else:
    print("x is not greater than y")
x is greater than y

Participation

-Calculate the total sum of two numbers, if it is equal to 200, print 200, if otherwise, print the sum.

num1 = 200
num2 = 300
sum = num1 + num2

print(str(sum) + "You don't need a condtional for this" )
500You don't need a condtional for this
var hrs = 10
var salary = ""
var experienced = true

if (hrs >= 10) {
    salary = "150k"
}
else if (hrs >= 8) {
    salary = "90k"
}
else {
    salary = "50k"
    experienced = false
}
console.log("This person has...\n" + "Salary: " + salary + "\n" + "Experience: " + experienced)
This person has...
Salary: 150k
Experience: true
product = {"expired":false, "cost":10}

if (product["expired"] == true) {
    console.log("This product is no good")
}
else {
    if (product["cost"] > 50) {
        console.log("This product is too really expensive!")
    }
    else if (product["cost"] > 25) {
        console.log("This is a regular product")
    }
    else {
        console.log(" This product is cheap")
    }
}
 This product is cheap
class question:
    def __init__(self, base, answer):
        self.base = base
        self.answer = answer


Questions = [
    "This is the first question on the\n (t) True\n (f) False\n",
    "What animal does bacon come from?\n (a) Pigs\n (b) Cows\n (c) Chicken\n",
    "Did America get eliminated by the Netherlands\n (t) True\n (f) False\n",
    "Was this test hard?\n (a) Yes extremely\n (b) No it was the easiest test of my life\n (c) I don't want to get this question right\n",

]

Q_Bank = [
    question(Questions[0], "t"),
    question(Questions[1], "a"),
    question(Questions[2], "t"),
    question(Questions[3], "b"),
]


def quiz(Q_Bank):
    score = 0
    for problem in Q_Bank:
        print(problem.base)
        rsp = input(problem.base)
        if rsp.lower().strip() == problem.answer:
            print("\nYour answer " + rsp + " matches the correct answer which was " + str(problem.answer))
            score += 1
        else:
            print("\nYour answer " + rsp + " doesn't match the correct answer which was " + str(problem.answer))
    if score >= 1:
        print("You got " + str(score)+" out of " + str(len(Q_Bank)) + " points so you have passed this test.")
    else: 
        print("You got " + str(score)+" out of " + str(len(Q_Bank)) + " points so you have failed this test.")


quiz(Q_Bank)
This is the first question on the
 (t) True
 (f) False


Your answer t matches the correct answer which was t
What animal does bacon come from?
 (a) Pigs
 (b) Cows
 (c) Chicken


Your answer a matches the correct answer which was a
Did America get eliminated by the Netherlands
 (t) True
 (f) False


Your answer t matches the correct answer which was t
Was this test hard?
 (a) Yes extremely
 (b) No it was the easiest test of my life
 (c) I don't want to get this question right


Your answer b matches the correct answer which was b
You got 4 out of 4 points so you have passed this test.