Unit 3.3 Notes

Video 1

Learning Objective

Express an algorithm that uses sequencing without using a programming language

Algorithims

  • Algorithms can be expressed in a variety of ways and can be executed by programs which are implemented using programming languages.
  • An algorithm is a finite set of instructions that accomplish a specific task, us as humans, do algorithms on a daily basis.

3 Steps of Algorithms

1. Sequencing

  • Sequencing is doing steps in order.

3. Selection

  • Selection is when the programmer decides between two different outcomes.

3. Iteration

  • Iteration is when you have to repeat a step until that condition is fulfilled.

Video 2

Vocabulary

  • algorithm- finite set of instructions that accomplish a specific task, composed of sequencing, selection, and iteration.
  • selection- a section of code is run only if a condition is met.
  • iteration- repeating steps or instructions over and over again
  • sequencing- outline or set of steps that we do and follow in order that they are given
  • variable- you can store an actual value, the value of a variable in another variable, the result of an operation, or result of a procedural call

Video 3

Arithmic Operators

  • plus signs are addition
  • subraction signs are subtraction
  • asterik/star is multiplication
  • slash indicates division

Unit 3.4

Video 1

Vocabulary

  • String: a sequence of characters
  • Len: finds the number of characters in a string (length)
  • String concatenation: combines two or more strings into one (combines words/letters)
  • Substring: a part of a existing string

Hacks

3.3 Video 1 Hacks

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

for i in numbers:
    if (numbers[i] % 2 == 0):
        evens.append(numbers[i])

print(evens)
[0, 2, 4, 6, 8, 10]
  • Sequencing: when the code runs through the all steps.
  • Iteration: when the code goes through the numbers "for i in numbers"
  • Selection: when the code picks even numbers by using the code "if (numbers[i] % 2 == 0);"
i = 1
starString = "*"
while i <= 5:
  j = 1
  while j <= i:
    print ("*", end= "")
    j += 1
  print ()
  i += 1
*
**
***
****
*****
  • Sequencing: when the code runs through the all steps.
  • Iteration: when the code line "while i <= 5" runs because it repeats until the asteriks reach 5.
  • Selection: when the code line "while j <= i" runs because it chosses j.

3.3 Video 2 Hacks

Code segment

a ⟵ 7

b ⟵ 1

c ⟵ 3

d ⟵ 4

a ⟵ b

b ⟵ c + d

d ⟵ b

find the value for a, b, c, d

My answer:

  • a = 1
  • b = 7
  • c = 3
  • d =

Code Segment

hot ⟵ true

cold ⟵ false

cold ⟵ hot

hot ⟵ cold

What are the values of hot and cold after executing the code segment?

  1. the value of hot is true, the value of cold is true
  2. the value of hot is false, the value of cold is true
  3. the value of hot is true, the value of cold is false
  4. the value of hot is false, the value of cold is false

My Answer:


Creating my own two code segments

Consider the following code segment:

  • num1 ⟵ 25
  • num2 ⟵ 15
  • num3 ⟵ 30
  • num2 ⟵ num3
  • num3 ⟵ num1
  • num1 ⟵ num2

DISPLAY(num1)

DISPLAY(num2)

DISPLAY(num3)

What is displayed after running this code segment?

  1. 25 15 30
  2. 30 30 25
  3. 30 15 30
  4. 15 30 25
Click for the answer! 2. because for num 1 the value is replaced by num 3's value which is 30. For num 2 the value is 30 because its replaced by num 1's value which was originally 25 but then was replaced by num 3's value 30. For num 3, the value is 25 because it's value is replaced by num 2 which num 2's value was replaced by num 1's.

Consider the following code segment:

  • p ⟵ 10
  • q ⟵ 20
  • r ⟵ 30
  • s ⟵ 40
  • p ⟵ q
  • q ⟵ r
  • s ⟵ q
  • r ⟵ p

What is the value of r as a result of running this code segment

  1. 10
  2. 20
  3. 30
  4. 40
Click for the answer! 2. because q is the variable assigned to p and q's value is 20.

Sequencing

Problem 4 Answer

  • num1 = 6
  • num2 = 11

3.4 Video 1 Hacks

Test 1

My Answer:

  • SmithB@gmail.com

Test 2

My Answer:

  • word1 <- "computer"
  • word2 <- "textbooks"
  • length1 <- len(word1)/2 = 4
  • length2 <- len(word2)/3 = 3
  • first <- substring(word1, 2, len1) = ompu
  • second <- substring(word2, len2+3, len2) = ook
  • newWord <- concat(first, second)

DISPLAY(newWord)

Answer: ompuook