3.3 Video 1

numbers = [0,1,2,3,4,5,6,7,8,9,10]
evens = []

# sequence --> all of the steps here
for i in numbers: # iteration
    if (numbers[i] % 2 == 0): # selection
        evens.append(numbers[i])

print(evens)
[0, 2, 4, 6, 8, 10]
i = 1
starString = "*"
# sequence --> all of the steps of the algorithm
while i <= 5: # iteration iterates through steps
  j = 1
  while j <= i: # selection
    print ("*", end= "")
    j += 1
  print ()
  i += 1
*
**
***
****
*****
animals = ["lion", "whale", "cat", "dog"]
pets = []

# sequencing: set of steps the code follows
for i in animals: # iteration: iterating through each item of the list
    if (i == "cat" or  i == "dog"): # selection: selects the item if it corresponds to a common house pet
        pets.append(i)

print("Here are some pets:")
print(pets)
Here are some pets:
['cat', 'dog']
words = ["racecar", "python", "code"]

# sequence: set of steps in the algorithm, checks if word is palindrome
for i in words: # iteration: iterates through the list
    if i == i[::-1]: # selection: if the order of characters in an entry is the same going from the start and end, then the item is selected
        print("The word " + i + " is a palindrome.")
    else:
        print("The word " + i + " is not a palindrome.")
The word racecar is a palindrome.
The word python is not a palindrome.
The word code is not a palindrome.

3.3 Video 2

  1. a = 1, b = 7, c = 3, d = 7
  2. The value of hot is true, the value of cold is true
  3. Sequence 1:

a <-- 6 b <-- 2 c <-- 3 d <-- 5 e <-- 1

b <-- a * c c <-- d + e e <-- a

Values: a = 6, b = 18, c = 6, d = 5, e = 6

a and d are unchanged b changes to the a times c(6*3) c changes to d + e(5+1)(note e is changed after the statement, so it retains the original value) e changes to a

Sequence 2:

totalscore <-- 9 roundScore <-- 2 penalty <-- 3 timeouts <-- 1 multiplier <-- 2 reset <-- 0

roundScore <-- roundScore + timeouts * multiplier timeouts <-- reset multiplier <-- reset roundScore <-- roundScore - penalty totalscore <-- totalscore + roundScore penalty <-- reset

Values: toatalscore = 10, roundScore = 1, penalty = 0, timeouts = 0, multiplier = 0, reset = 0

roundScore becomes the roundScore plus timeouts times the multiplier(2 + 1*2). timeouts is reset to 0. multiplier is set to 0. penalty(3) is subtracted from roundScore (4-3). roundScore becomes 1. roundScore is added to totalscore. totalscore is 10(9+1) penalty is reset to 0.

  1. num1 = 6, num2 = 11

3.4 Video 1

  1. SmithB@gmail.com
  2. ompuook

Blog

Through this lesson, I learned about sequencing, selection, and iteration. These can be used in an algorithm in order to further purpose. String length and concatenation allow for different values of strings to be manipulated and stored. This allows for greater use of strings and more implementation in code.

Vocab: Sequencing: doing steps in order, for example, doing the first step then the second then the third, etc Selection: when the programmer decides between two different outcomes Iteration when you have to repeat a step until that condition is fulfilled