Day 3 HW/Notes
Boolean Expressions
- Boolean= A data type with two possible values: true or false
Boolean and Binary
- Boolean math and binary notation both use the same two ciphers: 1 and 0
- Binary numbers may be composed of many bits adding up in place-weighted form to any finite value, or size
KNOW
- A Boolean value is either TRUE or FALSE
Logical Operators
- AND : returns TRUE if the operands around it are TRUE
- OR : returns TRUE if at least one operand is TRUE
- NOT : returns TRUE if the following boolean is FALSE
Conditionals
- Selection: uses a condition that evaluates to true or false
- Algorithm is a finite set of instructions that accomplish a specific task
Nested Conditionals
- statements consisting of conditional statements within other conditional statements
- Utilizes "if else" statements within "if else" statements
One in Python
# Here is a python template for you to use.
expired = False
cost = 50
if(expired):
print('this product is no good')
else:
if (cost > 50):
print('this product is too expensive')
elif (cost < 25):
print('this is a cheap product')
else:
print('this is a regular product')
One in JavaScript
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 expensive!11111")
}
else if (product["cost"] > 25) {
console.log("this product normal")
}
else {
console.log("cheap")
}
}
questions = {
"Which letter is farthest left on the keyboard?":["a. L","b. U", "c. S", "d. N"],
"Which company isn't a computer company?":["a. Apple", "b. Lenovo","c. Nike", "d. HP"],
"What coding language do we mainly use in class?":["a. HTML","b. CSS", "c. JavaScript", "d. Python"]
}
answers = {
"Which letter is farthest left on the keyboard?":"c",
"Which company isn't a computer company?":"c",
"What coding language do we mainly use in class?":"d"
}
score = 0
print("Ready for the computer quiz?")
for q,a in questions.items():
print(q)
print(*a)
inp = input("Enter Your Answer")
if(answers.get(q)==inp):
score = score +1
else:
print("Try again")
break
print('Final Score:', score)