3.1 & 3.2 Hacks (Vardaan and Navan)
Vardaan and Navan's Hacks 3.1-3.2
- 3.1 Variables Assignment 1 Hacks
- 3.1 Variables and Assignment Video 2 Hacks
- 3.2 Data Abstraction Video 2 Hacks
3.1 Variables Assignment 1 Hacks
- You want to store the number of apples in a shop. What is the best variable name and data type?
Answer: numApples and integer
EXPLANATION: the number of apples is a whole number, so it is best expressed as an integer.
- 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?
Answer: isCold and boolean
EXPLANATION: the state of being cold is a binary setting (either true or false), which is why it should be boolean.
- How do you store the ID numbers for the students in the classroom? Choose the best variable name and data type
Answer: IDnumber and string
EXPLANATION: the ID number is constantly changing and is a list of numbers next to each other, so instead of an integer, it is best expressed as a string.
- Is itisRainingtodayinsandiego a better option than isRaining?
Answer: no
EXPLANATION: this is way too complicated, isRaining is much simpler and broader
- Which of the following types of data is best for a true or false question?
Answer: Boolean
EXPLANATION: Boolean is true/false
- What is the difference between an integer and string of numbers?
Answer: An integer can be changed with addition and subtraction and a string is a set number or string of letters.
3 Practice Questions
- What is the best way to determine if John was money?
isMoney, boolean
- What is the best way to determine Manny’s phone number?
phoneNumber, string
- What is the best way to store all of Felipe’s pets?
petsOwned, string
3.1 Variables and Assignment Video 2 Hacks
-
Consider the following code segment: currentScore ⟵ 10
highScore ⟵ currentscore
currentScore ⟵ 7
Answer:
currentScore = 7
highScore = 10
-
Consider the following code segment: num1 ⟵ 4
num2 ⟵ 6
num1 ⟵ num 2
Answer:
num1: 6
num2: 6
-
Consider the following code segment: num1 ⟵ 25
num2 ⟵ 15
num3 ⟵ 30
num2 ⟵ num3
num3 ⟵ num1
num1 ⟵ num2
Answer:
num1: 30
num2: 30
num3: 25
-
Consider the following code segment: p ⟵ 10
q ⟵ 20
r ⟵ 30
s ⟵ 40
p ⟵ q
q ⟵ r
s ⟵ q
r ⟵ p
Answer:
r = 20
-
Consider the following code segment first ⟵ true
second ⟵ false
second ⟵ first
first ⟵ second
Answer:
first: true
second: true
-
Consider the following code segment a ⟵ 10
b ⟵ 20
c ⟵ 30
d ⟵ 40
x ⟵ 20
b ⟵ x + b
a ⟵ x + 1
d ⟵ c / d + 2
Answer:
a = 21
b = 40
c = 30
d = 50
3.2 Data Abstraction Video 2 Hacks
-
Consider the following code segment scores1 <- [89, 78, 92, 63, 95, 88]
scores2 <- [92, 79, 97, 63]
scores1 <- scores2
Answer:
score2 = [92, 79, 97, 63]
-
Consider the following code segment listA <- [“Sam”, “Ann”]
listB <- [“Jamal”, “Tamara”]
listB <- listA
listA <- listB
Answer:
listA = [“Sam”, “Ann”]
-
Consider the following code segment [“Red”, “Orange”, “Yellow”, “Green”, “Blue”, “Purple”]
Answer:
The length of the list is 6
-
What is the index number of “Purple” in this list? [“Red”, “Orange”, “Yellow”, “Green”, “Blue”, “Purple”]
Answer:
6
Correct Answer:
5 because it starts with 0
-
Which of the following types of data can be stored in a list?
Answer:
Booleans, Strings, and Floats
- Which of the following variables is a float?
- Apples
- -106.2
- 34
- True
Answer:
-106.2 because thats the only decimal
- If a list has a length of 24 items, what is the index number of the 17th item?
- 21
- 17
- 16
- 69
Answer:
16 because first one is 0
- A variable is permanent and cannot be changed later on.
- True
- False
Answer:
False
-
Which of the following is true about the list? [“Apples”, 42.0, “Bananas”, 0.5, “Avocado”, -902.2, “Lychee”, 6.9, “Orange”, 7.2]
Answer:
The list has floats, strings, and the index of “Avocado” is also 4