Lesson 1/2 Hacks
languages_list = []
languages_list = ["Python", "C++", "JavaScript", "other", "other"]
languages_list = []
languages_list = ["Python", "C++", "JavaScript", "other", "other"]
print(languages_list)
languages_list = []
languages_list = ["Python", "C++", "JavaScript"]
print(languages_list[0])
listA = []
listA = [1, 55, 8, 2, 76]
listB = []
listB = [22, 7, 13]
listA = listB
print(listA)
typeAnimals = ["Cats", "Dogs", "Rabbits", "Pigs"]
numAnimals = [5, 10, 15, 20]
typeAnimals = ["Cats", "Dogs", "Rabbits", "Pigs"]
numAnimals = [5, 10, 15, 20]
joinAnimals = typeAnimals + numAnimals
print(joinAnimals)
Binary Hacks
Convert these binary notation to decimal notation. (the way we normally count)
- The binary number 111.
1 + 2 + 4 =
7
- The binary number 1011.
1 + 2 + 8 =
11
- The binary number 1101011.
1 + 2 + 8 + 32 + 64 =
107
Convert the decimal notation to binary notation. (You can use the Binary Math from Mr. Yeung or the one you have)
- 12
4 + 8 = 12
1100
- 44
8 + 4 + 32 = 44
101100
- 254
255 - 1 = 254
11111110
Extra Binary Hacks if you changed your bits to 24
Convert decimal notation to binary notation.
- 57345
Click for the answer!
1110000000000001
- 16777215
Click for the answer!
111111111111111111111111
- 11184810
Click for the answer!
101010101010101010101010
Convert the binary notation to decimal notation
- 101011101010
Click for the answer!
2794
- 10011100000
Click for the answer!
1248
- 1101001000101000
Click for the answer!
53800
Homework/Hacks
Consider the following code segment:
- scores1 <- [89, 78, 92, 63, 95, 88]
- scores2 <- [92, 79, 97, 63]
- scores1 <- scores2
What are the contents of scores1 after the code segment is executed?:
- [92, 79, 97, 63]
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?
- ["Sam", "Ann"]
Though value of listB changes to match listA, listA remains the same due to taking on the value of the new listB.
What is the length of this list? ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
- 6
What is the index number of "Purple" in this list? ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
Count starts at 0, therefore there is index 5.
Which of the following types of data can be stored in a list?
- All of the above
Note: Any type of data can be stored within a list. A list can contain a mix of types of data.
Which of the following variables is a float?
- -106.2
Note: A float is a decimal number.
If a list has a length of 24 items, what is the index number of the 17th item?
Index starts at 0, therefore the 17th item would be the 16th index.
A variable is permanent and cannot be changed later on.
- 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]
1 and 4
The list has floats and string variable types.
The index of "Avocado" is 4.