Vocab

Booleans- Recongnize true/false.

Iteration- Way that code goes through a segment

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</li> </ul>

    2. 10(D) ≠ 0110(B)

    • A. True</li>
    • B. False
    • </ul>

      3. 56(D) ≥ 111000(B)

      • A. True</li>
      • B. False
      • </ul>

        3. 99(D) < 1110011(B)

        • A. True</li>
        • B. False
        • </ul> </div> </div> </div>

          Now, complete the binary truth tables

          AND Operator
          Value 1 Value 2 Result
          1 True 1
          True 0 1
          False 1 0
          0 False 0
          OR Operator
          Value 1 Value 2 Result
          1 1 True
          1 0 False
          0 False 0
          0 0 False
          Not operator
          Not Value Result
          Not BLANK 0
          Not 0 BLANK

          Python Practice

          # Practice with these statements
          
          print(20 == 20) # How can you change the operator to print a value of False? By changing the sign.
          
          
          x = 40
          y = 20
          z = 10
          print(x > y + z) # How can this return true by only manipulating the operator? Change the x, y, and z value in order to make the sum of Y and Z equal to X.
          
          # Manipulate the variables x, y, and z to make the below statement return true
          print(30 == 30)
          
          True
          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.</li>
          4. 75
          5. </ol>

            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.</li>
            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.
            5. </ol>

              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</li> </ol>

                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</li>
                2. If-else statement
                3. </ol>

                  Using Python

                  </div> </div> </div>
                  animals = ["lion", "tiger", "wildebeest", "shark", "jellyfish", "blobfish", "raven"]
                  
                  for i in animals:
                      if i == "wildebeest" or i == "lion": 
                          print (i  + " Fun Fact: They live in the desert")
                  
                  # 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
                  
                  lion Fun Fact: They live in the desert
                  wildebeest Fun Fact: They live in the desert
                  

                  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
                  Chickendict = {
                    "Food Item:" " Chicken Alfredo"
                    " Meat:" "Chicken"
                    " Time to Prepare:" "60 Minutes"
                  }
                  print (Chickendict)
                  
                  Cheesedict = {
                    "Food Item:" " Cheese Quesadilla"
                    " Meat:" "None"
                    " Time to Prepare:" "10 Minutes"
                  }
                  print (Cheesedict)
                  
                  Beefdict = {
                    "Food Item:" " Beef Wellington"
                    " Meat:" "Beef"
                    " Time to Prepare:" "150 Minutes"
                  }
                  print (Beefdict)
                  
                  {'Food Item: Chicken Alfredo Meat:Chicken Time to Prepare:60 Minutes'}
                  {'Food Item: Cheese Quesadilla Meat:None Time to Prepare:10 Minutes'}
                  {'Food Item: Beef Wellington Meat:Beef Time to Prepare:150 Minutes'}
                  

                  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?
                  </div>