Unit 3 Sections 1-2 Hacks
3.1
Variables and Assignments 1
Score: 6/6
-
1; in a store the number of apples can change from coustomers taking them and the store restocking them. This means that there's addition and subtraction is going on, which tells us the the variable type is an integer. Which is why I chose 1 as my answer.
-
3; the variable type must be boolean because we're looking for a True or False output this leaves choices 2 and 3 but 3 is chosen since "isCold" is more specific than "weather".
-
1; the variable type is string since ID numbers can't be added or subracted by a value, leaving 1 as the answer.
-
2; the variable is too long.
-
1; only booleans have the ablity to store a variable as true or false.
-
4; integers have the ability to preform operations on themselves while strings can only store a "dialague" of numbers and not an actual integer values.
Making Questions
- You work at a store and you want to make a list of names for all the items the store has, which of the following variable types will most likly be used?
A. isFruit, boolean\ B. itemPrice, float\ C. itemName, string\ D. numberOfItems, integer
Answer: C. itemName, string
- As a weatherman you need to tell if the weather is hot or not, how would you name this vaariable and what would be its data type?
A. isHot, boolean\ B. isHot, integer\ C. weatherTemperature, string\ D. weatherTemperature, float
Answer: A. isHot, boolean
- What is the best way to store a variable which is suppose to help with adding whole numbers?
A. numAdd, integer\ B. numAdd, float\ C. isPositive, boolean\ D. isPositive, string
Answer: A. numAdd, integer
Variables and Assignments 2
Practice Qustions
- 3; the ELSE block of the code is used since num1 < num2 and the second IF block is used since num2 ≥ num3 which makes the answer 8 + 4 + 4 which can be simplified to 16
- 2; num1 is set to 10 num2 is set to 10 and num3 is set to 10 as well which makes the sum 10 + 10 + 10 which can be simplified to 30
- 3; the latest thing ran sets the score to 7
- 2; the latest value sets highScore as currentScore and currentScore is 10
- 4; num1 is set to num2 so both of them have the same value
- 2; num1 has the value of num2 which has the value of num3 which is 30, num2 has the value of num3 which is 30, and num3 has the value of num1 which is 25 so 30 30 25 will be displayed
- 2; r is assigned as p which is assigned as q and since q is 20 so is r
- 3; second is assigned as first which is assigned as true so both first and second are true
- 21 40 30 2.75; b has the value of 40 since it's equal to x + b which is 20 + 20, d has a value of 2.75 since it's equal to c/d + 2 which is the same as 30/40 + 2, a has a value of 21 since it's equal to x + 1 which is 20 + 1 which can be simplified to 21, and c is just 30
Making Questions
Consider the following code segment
a ⟵ 5\ b ⟵ 10\ c ⟵ 20\ a ⟵ a + b\ c ⟵ c - a\ b ⟵ c + b
- What is the value of a?
A. 20\ B. 15\ C. 10\ D. 5
Answer: B. 15
- What is the value of b?
A. 20\ B. 15\ C. 10\ D. 5
Answer: C. 10
- What is the value of c?
A. 20\ B. 15\ C. 10\ D. 5
Answer: D. 5
Consider the following code segment
a ⟵ 10\ b ⟵ 2\ c ⟵ 8\ DISPLAY(a)\ a ⟵ a - b\ c ⟵ a + c\ DISPLAY(a)\ DISPLAY(c)
- What will be displayed after this code is ran?\
A. 10, 10, 8\ B. 10, 12, 8\ C. 10, 8, 16\ D. 10, 10, 16
Answer: C. 10, 8, 16
Consider the following code segment
a ⟵ 9\ b ⟵ 5\ c ⟵ 3\ a ⟵ a - b\ c ⟵ a - c\ b ⟵ a + c\ DISPLAY(a)\ DISPLAY(b)\ DISPLAY(c)
- What is the value of B?
A. 2\ B. 3\ C. 4\ D. 5
Answer: D. 5
- What is the value of C?
A. 1\ B. 2\ C. 3\ D. 4
Answer: A. 1
languages_list = []
languages_list = ["Python", "C++", "JavaScript", "Java", "C#"]
## To change the length to 5 I just added more variables in the list until it got to 5
- Change the following code to print out the list.
languages_list = []
languages_list = ["Python", "C++", "JavaScript"]
print(languages_list)
## For this I just added the name of the list in the parentheses in print()
- Change the following code to print out only "Python"
languages_list = []
languages_list = ["Python", "C++", "JavaScript"]
print(languages_list[0])
## Since lists start at 0 you put that number in the brackets which would then print the value at that point which is, in this case, "Python"
- Replace contents/data of listA with contents/data from listB.
listA = []
listA = [1, 55, 8, 2, 76]
listB = []
listB = [22, 7, 13]
listA = listB
print(listA)
##
- Make 2 lists:
- a list of string data
- a list of number data
- the length of the each list is a minimum of 4
- change the names of the lists
listA = ["a", "b", "c", "d", "e"]
listB = [1, 2, 3, 4, 5]
A = listA
B = listB
print(A + B)
- Combine the list to contain all of the data from both lists.
listA = ["a", "b", "c", "d", "e"]
listB = [1, 2, 3, 4, 5]
listC = listA + listB
print(listC)
Binary
Score: 3/3
- 7
- 11
- 107
Score: 3/3
- 1100
- 101100
- 11111110
Homework Hacks
Score: 9/9
- 4; since the data in scores1 is from scores2
- 1; in the 3rd step listB is the data from listA and then, in step 4, listA is the data from listB which is the same as the original listA
- 3; since each string is counted as 1 item, and there are 6 strings in total
- 4; the index of lists starts at 0 which makes "purple" the 5th item in the list
- 4; lists can store all data types
- 2; a float is a number which has a decimal point
- 3; since the index starts at 0 the 17th item would have an index at 16
- 2; variables typically can be changed
- 6; the answer can't be 2 since there is a 1:1 float:string ratio and it can't be 3 since the list has a length of 10. This eliminates 5 and 7 and since 1 and 4 are true the answer is 6