3.1 Homework/Hacks

  • You want to store the number of apples in a shop. What is the best variable name and data type?

    • #1 numApples, integer. This Variable accurately describes the information being stored. Data Type must be integer to allow for mutation.
  • You are storing true or false in a variable that asks if the classroom is cold. What is the best variable name and data type?

    • #3 isCold, boolean. It can either be cold or not (true/false) which is why the data type must be Boolean. isCold describes the situation.
  • How do you store the ID numbers for the students in the classroom? Choose the best variable name and data type:

    • IDnumber, string. Name is descriptive and concise. The data type is string as it does not need to be mutated
  • Is itisRainingtodayinsandiego a better option than isRaining?

    • No, isRaining is simpler and more efficient.
  • Which of the following types of data is best for a true or false question?

    • Booleans store true or false.
  • What is the difference between an integer and string of numbers?

    • Integer stores numbers and a string stores the numbers as text. Integers can be mutated unlike strings. #4 is right as it has two correct statements.
  • My own scenarios

    • Storing Profile Names
      • profileName, string
    • Storing Grades
      • grade, integer
    • Storing if I have my own Car
      • Car, boolean

3.2 Homework/Hacks

  • Consider the following code segment: What are the contents of scores1 after the code segment is executed?:

     scores1 <- [89, 78, 92, 63, 95, 88]
     scores2 <- [92, 79, 97, 63]
     scores1 <- scores2
    1. [89, 78, 92, 63, 95, 88]
    2. [89, 78, 92, 63, 95, 88, 92, 79, 97, 63]
    3. [92, 79, 97, 63, 89, 78, 92, 63, 95, 88]
    4. [92, 79, 97, 63]
    • 4: Data is not being Appended from scores2 to scores1.
  • Consider the following code segment:
     listA <- ["Sam", "Ann"]
     listB <- ["Jamal", "Tamara"]
     listB <- listA
     listA <- listB
    What are the contents of listA after the code segment is executed?
    1. ["Sam", "Ann"]
    2. ["Jamal", "Tamara"]
    3. ["Sam", "Ann", "Jamal", "Tamara"]
    4. ["Jamal", "Tamara", "Sam", "Ann"]
    • 1
  • What is the length of this list? ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
    1. 5
    2. 7
    3. 6
    4. 4
      • 6
  • What is the index number of "Purple" in this list? ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
    1. 7
    2. 0
    3. 6
    4. 5
      • 4
  • Which of the following types of data can be stored in a list?
    1. Boolean
    2. String
    3. Float
    4. All of the above
      • 4: All can be stored in a list.
  • Which of the following variables is a float?

    1. Apples
    2. -106.2
    3. 34
    4. True
      • 2
  • If a list has a length of 24 items, what is the index number of the 17th item?

    1. 21
    2. 17
    3. 16
    4. 69
      • 3
  • A variable is permanent and cannot be changed later on.

    1. True
    2. False
      • 2
  • Which of the following is true about the list? ["Apples", 42.0, "Bananas", 0.5, "Avocado", -902.2, "Lychee", 6.9, "Orange", 7.2]

    1. The list has floats and string variable types.
    2. The ratio of float variables to string variables is 2:1.
    3. The length is 9.
    4. The index of "Avocado" is 4.
    5. All of the above
    6. 1 and 4
    7. 1, 3, and 4
      • 6