LESSON PLAN 3
lesson 3 for class
- Lesson 3.5 Finn/Jake
- Relational Operators
- Logical Operators
- Hacks
- Answer:
- Lesson 3.6 Paaras/Shruthi
- Lesson 3.7 James
- Rubric for hacks:
What is a Boolean
- The defention of a Boolean is a denoting a system of algebraic notation used to represent logical propositions, especially in computing and electronics.
- A boolean expresions are either true or false.
- Testing if two numbers or variables are equal is a common example.
- For example: The sky is blue = True
- What do we use to represent them? (Hint think of how domain/range of graph is answered)
- How is binary related to this?
- How could this be used when asked a question?
Examples (Not part of homework)
Type the code down below for these two example
- Try to make a statement that determines if a variable "score" is equal to the number 3
- Try to make this score variable have an output if it equals 3
# The code for ex:1
i = "score"
if i == 3:
print(True)
# The code for ex:2
Relational Operators
- The mathmatical relationship between two variables
- Determines an output on whether or not the statement is true
- a=b, a>b, etc.
Examples (Not part of homework)
Type the code down below for these two example
- You have to be the age of 16 or older to drive
- Each rollercoaster cart holds 4 for people per cart
# Put the code for ex:1
age = 17
if age >= 16:
print(True)
# Put the code for ex:2
people = 3
if people <= 4:
print(True)
isRaining = False
result = not(isRaining)
print(result)
grade = 95
if grade > 70 and grade <= 100:
print("You passed the quiz")
lives = 1
score = 21
if lives <= 0 or score > 20:
print("end game")
Key Terms
- Selection: The specific block of code that will execute depending on the algorithm condition returning true or false.
- Algorithm: "A finite set of instructions that accomplish a specific task."
- Conditional Statement / If-Statement: A statement that affects the sequence of control by executing certain statements depending on the value of a boolean.
function isEven(parameter) {
if (parameter % 2 == 0) {
console.log("The number is even.");
}
else if (parameter % 2 != 0) {
console.log("The number is odd.")
}
}
isEven(4)
A computer science student such as yourself will see conditional statements in JavaScript a lot. Below is an example of one in action:
if (30 == 7) {
console.log("The condition is true")
}
That is one conditional statement, but this algorithm is too simple to have anything done with it. Below is an algorithm building on the previous algorithm:
if (30 == 7) {
console.log("The condition is true")
}
else if (30 != 7) {
console.log("The condition is false")
}
Conditional statements can be used for many a purpose. The algorithm above was quite simple, but conditionals can be found in more complex algorithms.
Essential Knowledge
Conditional statements ("if" statements) affect the sequential flow of control by executing different statements based on the value of a Boolean expression. The exam reference sheet provides:
In which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false
Hacks
- 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.
- 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.
- The hacks above was heavily derived from CollegeBoard. As a computer science student, you should be able to create an algorithm utilizing conditionals. Try something number-oriented if you get stuck. Creativity gets points.
Nested Conditionals
- Nested conditional statements consist of conditional statements within conditional statements
- they're nested one inside the other
- An else if inside of another else if
- Can be used for a varying amount of "else if statements." The first if statement can represent if two coditions are true. The first else if can represent if only one or the other is true. The last else if represents if neither of the conditions are true.
Take aways
- Learn how to determine the result of nested condtional statements
-
Nested conditional statements consist of conditional statements within conditional statements
-
One condition leads to check in a second condition
Writing Nested Conditional Statements
- Can be planned and writen out first
- Flow chart is a possibility. Ask a question. If the statement is false end the flowchart with one result. If it is true then repeat the process once more.
- If (condition 1)
- {
- first block of statements
- }
- else
- {
- IF (condition 2)
- {
- second block of statements
- }
- }
this statement is false make a new result. Finally if the statement is true make a final result
x = 2
y = 3
if x == y:
print("x and y are equal")
else:
if x > y:
print("x is bigger than y")
elif x < y:
print("x is smaller than y")
height = int(input("Welcom to the rollercoaster! \nWhat is your height in Inch? "))
age = int(input("What is your age?"))
if height < 48 :
print("Can't ride")
elif age < 12 :
photo = input("Adult tickets are $5 \nDo you want a photo taken? Y or N. ")
if photo=="Y":
print("The total bill is $8.")
if photo=="N":
print("The total bill is $5.")
elif age < 18:
photo = input("Adult tickets are $7 \nDo you want a photo taken? Y or N. ")
if photo=="Y":
print("The total bill is $10.")
if photo=="N":
print("The total bill is $7.")
else :
photo = input("Adult tickets are $12 \nDo you want a photo taken? Y or N. ")
if photo=="Y":
print("The total bill is $15.")
if photo=="N":
print("The total bill is $12.")
import random
global i
game = ["rock", "scissor", "paper"]
winning = ["paper", "rock", "scissor"]
i = 0
def gameStart():
randomNumber = random.randrange(0,2)
randomOne = game[randomNumber]
gamer = str(input("what will you do"))
print(gamer)
print(randomOne)
while True:
if winning[i] == gamer:
break
else:
i += 1
if randomNumber == i:
print("You win")
else:
if randomNumber == (i+1)%3:
print("Lose")
elif randomNumber == (i+2)%3:
print("Draw")
pre = input("Do you want a game?[yes/no]")
if pre == "yes":
gameStart()
randomNumber = random.randrange(0,2)
else:
print("Goodbye")
gameStart()
Plus | Binary | Octal | Hexadecimal | Decimal | Minus |
---|---|---|---|---|---|
00000000 | 0 | 0 | 0 | ||
00000000 | 0 | 0 | 0 | ||
00000000 | 0 | 0 | 0 |
Hacks
- Create 3 differnt flow charts representing nested statements and transfer them into code.
- Create a piece of code that displays four statements instead of three. Try to do more if you can.
- Make piece of code that gives three different recommandations for possible classes to take at a scholl based on two different condtions. These conditions could be if the student likes STEM or not.