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
- Storing Profile Names
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
- [89, 78, 92, 63, 95, 88]
- [89, 78, 92, 63, 95, 88, 92, 79, 97, 63]
- [92, 79, 97, 63, 89, 78, 92, 63, 95, 88]
- [92, 79, 97, 63]
- 4: Data is not being Appended from scores2 to scores1.
- Consider the following code segment:
What are the contents of listA after the code segment is executed?listA <- ["Sam", "Ann"] listB <- ["Jamal", "Tamara"] listB <- listA listA <- listB
- ["Sam", "Ann"]
- ["Jamal", "Tamara"]
- ["Sam", "Ann", "Jamal", "Tamara"]
- ["Jamal", "Tamara", "Sam", "Ann"]
- 1
- What is the length of this list?
["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
- 5
- 7
- 6
- 4
- 6
- What is the index number of "Purple" in this list?
["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
- 7
- 0
- 6
- 5
- 4
- Which of the following types of data can be stored in a list?
- Boolean
- String
- Float
- All of the above
- 4: All can be stored in a list.
Which of the following variables is a float?
- Apples
- -106.2
- 34
- True
- 2
If a list has a length of 24 items, what is the index number of the 17th item?
- 21
- 17
- 16
- 69
- 3
A variable is permanent and cannot be changed later on.
- True
- 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]
- The list has floats and string variable types.
- The ratio of float variables to string variables is 2:1.
- The length is 9.
- The index of "Avocado" is 4.
- All of the above
- 1 and 4
- 1, 3, and 4
- 6