This Group: Joselyn, Amitha, Naja, and Lina

3.1 Work

Practice Questions

Q: What would be the best variable name and data type to store a user's age in a program? age and Integer

  • A: name: age data type: integer

Q: What would be the best variable name and data type to store the number of students in your class? numStudents and Integer

  • A: name: numStudents data type: integer to add and subtract

Q: What would be the best variable name and data type to store the title of a movie? movieTitle and string

  • A: name: movieTitle data type: text(or string)

Q: What would be the best variable name and data type to store if someone's pet is a dog. isDog and Boolean

  • A: name: isDog data type: boolean

Score: 4/4

Practice Questions 2

You want to store the number of apples in a shop. What is the best variable name and data type?

  1. numApples, integer
  2. apples, text
  3. numApples, string
  4. isApples, boolean

My Answer: 1

Click for the answer! 1. Because the name is descriptive of what is stored. Also, the number of apples in the store can change so the integer lets you add a nd subtract to the number of apples.

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?

  1. weather, integer
  2. weather, boolean
  3. isCold, boolean
  4. cold, string

My Answer: 3

Click for the answer! 3. Because this is a true or false question. It is either cold or not, so the variable name describes the circumstance, then the boolean data type specifies true or false.

How do you store the ID numbers for the students in the classroom? Choose the best variable name and data type:

  1. IDnumber, string
  2. whatID, integer
  3. IDnumberofthestudentsintheclassroom, boolean
  4. IDnumberofthestudentsintheclassroom, integer

My Answer: 1

Click for the answer! 1. IDnumber because it is descriptive but not too long and innefective. it is also a string because it doesn't change and its a string of numbers.

Is itisRainingtodayinsandiego a better option than isRaining?

  1. Yes
  2. No

My Answer: 2

Click for the answer! 2. No, because it is too long and inefficient to use when trying to store variables.

Which of the following types of data is best for a true or false question?

  1. Boolean
  2. String
  3. Float
  4. All of the above

My Answer: 1

Click for the answer! 1. A boolean data type allows a variable to store true and false.

What is the difference between an integer and string of numbers?

  1. An integer is just a set data type while a string of numbers can be changed with addition and subtraction
  2. An integer can be letters and numbers while a string is just numbers
  3. An integer is just numbers while a string is just words
  4. An integer can be changed with addition and subtraction and a string is a set number or string of letters.

My Answer: 4

Click for the answer! 4. This is the only answer that has two true statements

Score: 6/6

Now, make at least 3 of your own practice questions making a scenario and then adding the variable name and data type. Add this to you blog!

Which of the following types of data is best for storing a number?

  1. Boolean
  2. String
  3. Float
  4. All of the above

My Answer: 3

Click for the answer! 3. An integer allows variables to be set to an integer and can be changed with math functions.

What should the name of a variable be when trying to find out how many guests there are?

  1. numPeople
  2. numberOfPeopleWhoAreAttending
  3. numChairs
  4. PeopleWhoAreNotAttending

My Answer: 1

Click for the answer! 1. It is short and it makes sense, it tells coders what exactly it does

When a variable is called customerOrder, what type of data will most likely be used?

  1. Boolean
  2. String
  3. Float
  4. All of the above

My Answer: 2

Click for the answer! 2. On a menu, there is mostly text and you have to store the text into a list, so a string would be the best choice.

Score: 3/3

3.2 Work

1. Your turn to interact, try it now!

Modify the list to change the length to 5.

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

languages_list.append("HTML")
languages_list.append("Lua")

print(languages_list)
['Python', 'C++', 'JavaScript', 'HTML', 'Lua']
languages_list = []
languages_list = ["Python", "C++", "JavaScript", "R", "Lua"]

print(languages_list)
['Python', 'C++', 'JavaScript', 'R', 'Lua']

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

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

languages_list_new = []
languages_list_new = ["Python", "C++", "JavaScript", "R", "Lua"]

print(languages_list_new)
['Python', 'C++', 'JavaScript', 'R', 'Lua']

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
foodList = ["Burger", "Fries", "Milkshake", "Nuggets"]
numList = [5, 10, 25, 100]

print(foodList)
print(numList)
['Burger', 'Fries', 'Milkshake', 'Nuggets']
[5, 10, 25, 100]

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

Hint! Use extend or append
foodList = ["Burger", "Fries", "Milkshake", "Nuggets"]
numList = [5, 10, 25, 100]

foodList.extend(numList)

print(foodList)
['Burger', 'Fries', 'Milkshake', 'Nuggets', 5, 10, 25, 100]

A Little Bit on Binary

  • A type of positional number system, with the base of 2 and uses exponents within it.
  • It is represented in zeroes and ones, each different column, lightbulb, or place representing a different value. From the right it starts as 2^0 which equals 1, then 2^1 = 2, then 2^2 = 4, and so on
  • It connects with data abstraction because the more complex data, calculating the value, is represented in binary with base of 2, however it is simplified to only show combinations of the digits zero and one.

Binary Hacks

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

  1. The binary number 111. 1 + 2 + 4 = 7
    Click for the answer! 7

  1. The binary number 1011. 1 + 2 + 0 + 8 = 11
    Click for the answer! 11

  1. The binary number 1101011. 1 + 2 + 0 + 8 + 0 + 32 + 64 = 107
    Click for the answer! 107

Score: 3/3

Convert the decimal notation to binary notation. (You can use the Binary Math from Mr. Yeung or the one you have)

  1. 12 = 0 + 0 + 4 + 8 --> 1100
    Click for the answer! 1100

  1. 44 = 0 + 0 + 4 + 8 + 0 + 32 --> 101100
    Click for the answer! 101100

  1. 254 = 0 + 2 + 4 + 8 + 16 + 32 + 64 + 128 --> 11111110
    Click for the answer! 11111110

Score: 3/3

Extra Binary Hacks if you changed your bits to 24

Convert decimal notation to binary notation.

  1. 57345 = 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8192 + 16384 + 32768 = 1110000000000001
    Click for the answer! 1110000000000001

  1. 16777215 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 32768 + 65536 + 131072 + 262144 + 524288 + 1048576 + 2097152 + 4194304 + 8388608 = 111111111111111111111111
    Click for the answer! 111111111111111111111111

  1. 11184810 = 0 + 2 + 0 + 8 + 0 + 32 + 0 + 128 + 0 + 512 + 0 + 2048 + 0 + 8192 + 0 + 32768 + 0 + 131072 + 0 + 524288 + 0 + 2097152 + 0 + 8388608 = 101010101010101010101010
    Click for the answer! 101010101010101010101010

Score: 3/3

Convert the binary notation to decimal notation

  1. 101011101010 = 0 + 2 + 0 + 8 + 0 + 32 + 64 + 128 + 0 + 512 + 0 + 2048 = 2794
    Click for the answer! 2794

  1. 10011100000 = 0 + 0 + 0 + 0 + 0 + 32 + 64 + 128 + 0 + 0 + 1024 = 1248
    Click for the answer! 1248

  1. 110100 10001 01000 = 0 + 0 + 0 + 8 + 0 + 32 + 0 + 0 + 0 + 512 + 0 + 0 + 4096 + 0 + 16384 + 32768 = 53800
    Click for the answer! 53800

Score: 3/3

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. [89, 78, 92, 63, 95, 88]
  2. [89, 78, 92, 63, 95, 88, 92, 79, 97, 63]
  3. [92, 79, 97, 63, 89, 78, 92, 63, 95, 88]
  4. [92, 79, 97, 63]

My Answer: 4

Click for the answer! 4. Because the data is not being appended from scores2 into scores1.

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"]
  2. ["Jamal", "Tamara"]
  3. ["Sam", "Ann", "Jamal", "Tamara"]
  4. ["Jamal", "Tamara", "Sam", "Ann"]

My Answer: 1

Click for the answer! 1. Because all of the data from listA "Sam" and "Ann" replace what is in listB. So if listB replaces what is in listA, "Sam" and "Ann" will still be the only data in that list.

What is the length of this list? ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]

  1. 5
  2. 7
  3. 6
  4. 4

My Answer: 6

Click for the answer! 3. The length of the list is 6.

What is the index number of "Purple" in this list? ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]

  1. 7
  2. 0
  3. 6
  4. 5

My Answer: 6 Corrections: This is wrong because the computer starts counting at 0, I forgot this and it is supposed to be the 5th one in the list

Click for the answer! 4. The index count starts at 0, making "Red" 0 and "Purple" index 5.

Which of the following types of data can be stored in a list?

  1. Boolean
  2. String
  3. Float
  4. All of the above

My Answer: 4

Click for the answer! 4. 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. Apples
  2. -106.2
  3. 34
  4. True

My Answer: 2

Click for the answer! 2. A float is a decimal number.

If a list has a length of 24 items, what is the index number of the 17th item?

  1. 21
  2. 17
  3. 16
  4. 69

My Answer: 3

Click for the answer! 3. An index count starts at 0 so the index number of a variable is one less than it's spot in the length.

A variable is permanent and cannot be changed later on.

  1. True
  2. False

My Answer: 2

Click for the answer! 2. False. Variables can be changed later on in the code.

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. The list has floats and string variable types.
  2. The ratio of float variables to string variables is 2:1.
  3. The length is 9.
  4. The index of "Avocado" is 4.
  5. All of the above
  6. 1 and 4
  7. 1, 3, and 4

My Answer: 6

Click for the answer! 6. The list has floats or decimals and strings, and the length is 10, the ratio of string to floats is 1:1, and the index number of "Avocado" is 4.

Score: 8/9