This Group: Arnav, Nicolas, Ben, and Luke

Notes

  • In pseudocode the relational operators are =, >, <, ≠, ≥, and ≤. Python uses != instead of ≠
    • These operators help determine the boolean value of a statement

Logical operators allow for boolean values to be evaluated

  • Pseudocode uses the logical operators NOT, AND, and OR

  • Javascript uses the same logic as Pseudocode, but uses different ways to represent the operators

  • An algorithm is a finite set of instructions that accomplish a specific task Conditional Statements: allow the code to act based on multiple conditions

  • User input or stored data use in order to receive different outputs from a set of code, and help achieve the general purpose of the algorithm Categories

    • 2 Broad Algorithms
  • In algorithms in order to print specific data or run certain tasks, to create further conditions in algorithms. We can use flowcharts to help display an easy to understand diagram of what we want a code segment to do.

  • A Nested conditional is a conditional inside of a conditional

Vocabulary

3.5 Hacks

Binary Practice

Using psuedocode operators determine if the statements are true or false. The number type will be indicated in parentheses.

1. 90(D) = 1000(B)

  • A. True
  • B. False

My Answer: False

Explanation: The Binary number is 8, which is not equal to 90

1000 = 0 + 0 + 0 + 8 = 8

2. 10(D) ≠ 0110(B)

  • A. True
  • B. False

My Answer: True

Explanation: This is true because the binary number is 6, which is not equal to 10, this is exactly what the statement is saying and is not equal to each other

0110 = 0 + 2 + 4 + 0 = 6

3. 56(D) ≥ 111000(B)

  • A. True
  • B. False

My Answer: True

Explanation: The answer to this question is true because when you find the number of the binary, it becomes 56 and that means that statement is true. The operator in the middle is greater than or equal to, and 56 is equal to 56

111000 = 0 + 0 + 0 + 8 + 16 + 32 = 56

3. 99(D) < 1110011(B)

  • A. True
  • B. False

My Answer: True

Explanation: This is true because when you find the binary's value in decimal, you get a value of 115. The operator here is less than, and 99 is less than 115 and the statement becomes true.

1110011 = 1 + 2 + 0 + 0 + 16 + 32 + 64 = 115

Now, complete the binary truth tables

AND Operator
Value 1 Value 2 Result
1 1 1
1 0 0
0 1 0
0 0 0
OR Operator
Value 1 Value 2 Result
1 1 1
1 0 1
0 1 1
0 0 0
Not operator
Not Value Result
Not 1 0
Not 0 1

Python Practice

# Practice with these statements
print("Part 1")
print(20 == 20) # How can you change the operator to print a value of False?
print (20 == 30) # Answer to Part 1, I just changed one of the values making the statement false

print()
print("Part 2") # Reason for adding a 0 is so it doesn't interfere with Part 3 Hacks
x0 = 30
y0 = 20
z0 = 10
print(x0 > y0 + z0) # How can this return true by only manipulating the operator?
print(x0 > y0 - z0) # I changed the addition to subtraction so it becomes 30 > 10
print(x0 >= y0 + z0) # In this line, I made the operator greater than or equal to because 30 is equal to 30

# Manipulate the variables x, y, and z to make the below statement return true
print()
print("Part 3")
x1 = 30
y1 = 20
z1 = 30
print(x1 == z1) # I can just change the value of z1 and make it 30 so the statement is true
x2 = 30
y2 = 20
z2 = 30
x2 = z2
print(x2 == z2) # I can also just set x2 to the value of z2, making this statement true
Part 1
True
False

Part 2
False
True
True

Part 3
True
True

3.6 Hacks

AP Prep

1. What is displayed by this code?

  • result <-- 75
  • IF result < 80 { DISPLAY("Please schedule a retake.") }
  • ELSE { DISPLAY("Nice job!") }
  1. Nice job!
  2. Display
  3. Please schedule a retake.
  4. 75

My Answer: 3

Explanation: The variable result is equal to 75 and when put into the if statement, it is less than so it is true and runs the first segment to display please schedule a retake.

2. How is an if statement different from an if-else statement.

  1. Extra words.
  2. An if statement will only go through a process if a condition is met. An if-else statement will go through code no matter the conditions.
  3. They are the exact same.
  4. An if statement will go through the entire code segment every single time and the if-else statement is always used in an algorithm, no matter the conditions.

My Answer: 2

Explanation: An if statement will only run code inside the block if it if the condition is met. However, in an if-else statement, if that statement is not true, then it will run the code in the else block, so code will be run whether the statement is true or false. 3. What would be most appropriate for this situation? Ben wants to check his bank account. If his car fuel is full, he will go to the bank. Otherwise, he will go home. If he goes to the bank, he will withdraw money only if his balance is above $1000.

  1. If statement
  2. If-else statement

My Answer: 2

This is a situation where events are dependent on one event. If Ben has a full tank of car fuel, then he will go to the bank, if that statement is false, then he will go home. Once he gets to the bank, it is another if-else statement because it depends if his account has money in it. If it does not have $1000 or higher, he will not deposit money, but if he does, he will deposit money.

4. What would be most appropriate for this situation? Luke wants to play basketball. If it is sunny outside he will go to the park to play basketball.

  1. If statement
  2. If-else statement

My Answer: 1

Explanation: If the statement is false, then nothing will happen, he probably will just stay home, but if it is true then he will go to the park and play basketball.

Using Python

animals = ["lion", "tiger", "wildebeest", "shark", "jellyfish", "blobfish", "raven"]

for i in animals:
    if i == "shark": # What boolean value does this statement cause?
        print("Fun Fact: The smallest shark is the dwarf lantern shark, and it is small enough to hold in your hand!")
    if i == "lion": # Lions live in the Desert
        print("Fun Fact: Lions live in the desert, and almost all of them are in Africa and they hunt during storms")
    else:
        print(i)

# Practice
# Using only one more if statement, alter the code to print out a statement saying if an animal lives in the desert, based on booleans
Fun Fact: Lions live in the desert, and almost all of them are in Africa and they hunt during storms
tiger
wildebeest
Fun Fact: The smallest shark is the dwarf lantern shark, and it is small enough to hold in your hand!
shark
jellyfish
blobfish
raven

3.7 Hacks

Exercise 1

  • Create dictionaries for multiple food items, with the listed specifications
    • Chicken Alfredo, Meat: Chicken, Time to Prepare: 60 minutes
    • Cheese Quesadilla, Meat: None, Time to Prepare: 10 minutes
    • Beef Wellington, Meat: Beef, Time to Prepare: 150 minutes
  • Used nested conditionals, determine which meal you can cook, given that a) you have no meat at home, and b) you only have 30 minutes to make the meal
chickenAlfredo = {
    "Name": "Chicken Alfredo",
    "Meat": True,
    "Time": 60,
}
cheeseQuesadilla = {
    "Name": "Cheese Quesadilla",
    "Meat": False,
    "Time": 10,
}
beefWellington = {
    "Name": "Beef Wellington",
    "Meat": True,
    "Time": 150,
}

def mealPrep(item):
  if item["Time"] <= 30:
    if item["Meat"] == False:
      print(item["Name"], "doesn't contain any meat, so this is a good choice")
  else:
    print(item["Name"], "takes too much time to cook and contains meat")

mealPrep(chickenAlfredo)
mealPrep(cheeseQuesadilla)
mealPrep(beefWellington)

# Answer Should be Cheese Quesadilla because it only takes 
Chicken Alfredo takes too much time to cook and contains meat
Cheese Quesadilla doesn't contain any meat, so this is a good choice
Beef Wellington takes too much time to cook and contains meat

Exercise 2

Make a flowchart(here is one we used) and write pseudocode for the following scenario.

  • Mr. Yeung would like to grade live reviews.
  • He wants to see if each student has at least 2 issues on their project. If they don't they receive a score of 2.0.
  • If they have at least 2 issues, check that they have completed at least 5 of their scrumboard tasks.
  • If they have completed 5 scrumboard tasks, give the student a 2.7. If they have not completed 5 scrumboard tasks, give them a score of 2.5. If they have completed more than 5 tasks, give them a score of 3.0.
  • How much would a student with 3 issues and 1 complete scrumboard task receive?

A student with 3 issues and 1 complete scrumboard task would recieve a 2.5, see the yellow line on the flowchart

issues = 3
scrumboardTask = 1
score = 0

print("This is your Score:")

if issues >= 2:
    if scrumboardTask == 5:
        score = 2.7
        print(score)
    elif scrumboardTask > 5:
        score = 3.0
        print(score)
    else:
        score = 2.5
        print(score)
else:
    score = 2.0
    print(score)