1. Your turn to interact, try it now!

Modify the list to change the length to 5.

languages_list = []
languages_list = ["Python", "C++", "JavaScript", "other", "other"]

2. Change the following code to print out the list.

languages_list = []
languages_list = ["Python", "C++", "JavaScript", "other", "other"]
print(languages_list)
['Python', 'C++', 'JavaScript', 'other', 'other']

3. Change the following code to print out only "Python"

languages_list = []
languages_list = ["Python", "C++", "JavaScript"]
print(languages_list[0])
Python

4. Replace contents/data of listA with contents/data from listB.

Print listA out afterward

listA = []
listA = [1, 55, 8, 2, 76]
listB = []
listB = [22, 7, 13]
listA = listB

print(listA)
[22, 7, 13]

5. 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
typeAnimals = ["Cats", "Dogs", "Rabbits", "Pigs"]
numAnimals = [5, 10, 15, 20]

6. Combine the list to contain all of the data from both lists.

Hint! Use extend or append
typeAnimals = ["Cats", "Dogs", "Rabbits", "Pigs"]
numAnimals = [5, 10, 15, 20]

joinAnimals = typeAnimals + numAnimals
print(joinAnimals)
['Cats', 'Dogs', 'Rabbits', 'Pigs', 5, 10, 15, 20]

Binary Hacks

Convert these binary notation to decimal notation. (the way we normally count)

  1. The binary number 111. 1 + 2 + 4 =
     7
  1. The binary number 1011. 1 + 2 + 8 =
     11
  1. 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)

  1. 12

4 + 8 = 12

1100

  1. 44

8 + 4 + 32 = 44

    101100

  1. 254

255 - 1 = 254

    11111110


Extra Binary Hacks if you changed your bits to 24

Convert decimal notation to binary notation.

  1. 57345
    Click for the answer! 1110000000000001

  1. 16777215
    Click for the answer! 111111111111111111111111

  1. 11184810
    Click for the answer! 101010101010101010101010

Convert the binary notation to decimal notation

  1. 101011101010
    Click for the answer! 2794

  1. 10011100000
    Click for the answer! 1248

  1. 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?:

  1. [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?

  1. ["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"]

  1. 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?

  1. 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?

  1. -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.

  1. 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. 1 and 4

  2. The list has floats and string variable types.

  3. The index of "Avocado" is 4.