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?
      1. 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?
      1. isCold, boolean (correct!)
  • Is itisRainingtodayinsandiego a better option than isRaining?
      1. No (correct!)
  • Which of the following types of data is best for a true or false question?
      1. boolean (correct!)
  • What is the difference between an integer and string of numbers?

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

  1. 7
  2. 10
  3. 6 6
  4. 30 30 25
  5. 20
  6. The value of first is true, and the value of second is true.
  7. 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 :)

  1. 7
  2. 11
  3. 107
  4. 1100
  5. 101100
  6. 11111110

Extra Hacks:

  1. 1110000000000001
  2. 111111111111111111111111
  3. 101010101010101010101010
  4. 2794
  5. 1248
  6. 53800

Homework/Hacks:

  1. [92, 79, 97, 63]
  2. ["Jamal", "Tamara"]
    • incorrect! ["Sam", "Ann"] is the right answer because listB's new value is now ["Sam", "Ann"], so list A is ["Sam", "Ann"].
  3. 6
  4. 5
  5. all of the above
  6. -106.2
  7. 16
  8. false
  9. 1 and 4

3.2 Video 2 classwork follow along

languages_list = []
languages_list = ["Python", "C++", "JavaScript"]
print(languages_list[0])
Python
listA = []
listA = [1, 55, 8, 2, 76]
listB = []
listB = [22, 7, 13]
listA.extend(listB)
print(listA)
# listA = listB
# print(listA)
[1, 55, 8, 2, 76, 22, 7, 13]
colorsYay = ["purple", "yellow", "red", "blue"]
numbersYay = [39, 3, 5, 8]

print(colorsYay)
print(numbersYay)
['purple', 'yellow', 'red', 'blue']
[39, 3, 5, 8]
colorsYay = ["purple", "yellow", "red", "blue"]
numbersYay = [39, 3, 5, 8]
combineYay = [numbersYay, str(colorsYay)]
print(combineYay)
[[39, 3, 5, 8], "['purple', 'yellow', 'red', 'blue']"]