Unit 3.1
Unit 3.1 Variables and Assignment 1 Hacks
- You want to store the number of apples in a shop. What is the best variable name and data type?
- numApples, integer (correct!)
- 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?
- isCold, boolean (correct!)
- Is itisRainingtodayinsandiego a better option than isRaining?
- No (correct!)
- Which of the following types of data is best for a true or false question?
- boolean (correct!)
What is the difference between an integer and string of numbers?
- An integer can be changed with addition and subtraction and a string is a set number or string of letters. (correct!) My Own 3 Questions: 1.Mr. Yeung and Mr. Mortensen want to keep track of all their students grade levels: sophomore, junior, senior. What is the best variable name and data type?
a. GradeLevel, integer
b. gradeLevel, string
c. gradelevelofmortandyeungsstudents, string
d. gradeLevel, float
answer: b. gradeLevel, string
2.I want to create code that displays whether the answer is correct or not correct for a math test, what is the best variable name and data type for this?
a. isRight, integer
b. correctAnswer, string
c. isCorrect, float
d. isCorrect, boolean
answer: d. isCorrect, boolean
3.I want to find out the number of books in the library, what is the best variable name and data type for this?
a. numBooks, integer
b. numbBooks, string
c. numberofbooksinlibrary, integer
d. numBooks, boolean
answer: a. numBooks, integer
Unit 3.1 Variables and Assignment 2 Hacks
- 7
- 10
- 6 6
- 30 30 25
- 20
- The value of first is true, and the value of second is true.
- I think this problem had a typo because I got, 21 40 30 2.75, I looked at the answer key and it says "Since c is 30 and d / 2 is 20, d is assigned the value 50." but the original problem is written as "d ⟵ c / d + 2"
My Own Problems: 1.given the following code segment
key ⟵ true
board ⟵ false
board ⟵ key
key ⟵ board
what is the value of key?
A: true
2.given the following code segment
a ⟵ 7
b ⟵ 1
c ⟵ 3
b ⟵ c
d ⟵ a + b + c
find the value of d
A: 13
3.given the code segment:
a ⟵ 7
b ⟵ 1
a ⟵ b
find the value of a and b:
A. a = 1, b = 1
4.given the code segment:
num1 ⟵ 5
num2 ⟵ 8
num3 ⟵ 10
nums ⟵ num1 + num2 + num3
find nums value:
A: 23
5.given the code segment:
a ⟵ 2
b ⟵ 3
c ⟵ 6
b ⟵ c
a ⟵ c
c ⟵ a
find the value of a, b, and c:
A. a = 6, b = 6, c = 6
6.given the code segment:
first ⟵ yes
second ⟵ no
first ⟵ second
second ⟵ first
what is the value of first and second?
A: first = no, second = no
Unit 3.2 Variables and Assignment 2 Hacks
Binary Hacks: I used my binary math to help :)
- 7
- 11
- 107
- 1100
- 101100
- 11111110
Extra Hacks:
- 1110000000000001
- 111111111111111111111111
- 101010101010101010101010
- 2794
- 1248
- 53800
Homework/Hacks:
- [92, 79, 97, 63]
- ["Jamal", "Tamara"]
- incorrect! ["Sam", "Ann"] is the right answer because listB's new value is now ["Sam", "Ann"], so list A is ["Sam", "Ann"].
- 6
- 5
- all of the above
- -106.2
- 16
- false
- 1 and 4
languages_list = []
languages_list = ["Python", "C++", "JavaScript"]
print(languages_list[0])
listA = []
listA = [1, 55, 8, 2, 76]
listB = []
listB = [22, 7, 13]
listA.extend(listB)
print(listA)
# listA = listB
# print(listA)
colorsYay = ["purple", "yellow", "red", "blue"]
numbersYay = [39, 3, 5, 8]
print(colorsYay)
print(numbersYay)
colorsYay = ["purple", "yellow", "red", "blue"]
numbersYay = [39, 3, 5, 8]
combineYay = [numbersYay, str(colorsYay)]
print(combineYay)