Chapter 3.3 and 3.4
Lesson Notes and hacks
- Notes
- Learning Objective
- Essential Knowledge
- Examples
- Video 3
- 3.4 Video 1: Strings
- Hacks
- Video 2 Hacks
- Final Thoughts on lesson/reflection
Learning Objective
Express an algorithm that uses sequencing without using a programming language
Essential Knowledge
- Algorithms can be expressed in a variety of ways and can be executed by programs which are implemented using programming languages.
- Every algorithm can be constructed using combinations of sequencing, selection, and iteration
An algorithm is a finite set of instructions that accomplish a specific task, us as humans, do algorithms on a daily basis.
Sequencing is doing steps in order, for example, doing the first step then the second then the third, etc.
Selection is when the programmer decides between two different outcomes.
Iteration is when you have to repeat a step until that condition is fulfilled.
Examples
Number 1:
Must be in order:
- Set largestNumber to 0, Get next number in list, If number is larger than largestNumber then set largestNumber to number, If there are more numbers in list, go back to Step 2, Display largestNumber
Number 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
Asnwer: all sums divided by 3 = 26.667
Answer: 3. 2 3
Answer: 2. 20
Video 3
-
A plus sign indicates addition: a + b
-
A subtraction sign indicates subtraction: a - b
-
An asterisk/star indicates multiplication: a * b
-
A slash indicates division: a / b
Answer: 29
3.4 Video 1: Strings
- String: sequence of characters in a string
- Len: finds a number of characters in a string
- String concatenation: combines two or more strings into one
- Substring: a part of a existing string
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)
- The sequencing is when the code runs through the steps so all of them combines
- the "for i in numbers" is the iteration because it appends the even numbers from the list
- The selection is "if (numbers[i] % 2 == 0):" because thats when the code picks the number, it picks the even numbers
i = 1
starString = "*"
while i <= 5:
j = 1
while j <= i:
print ("*", end= "")
j += 1
print ()
i += 1
2.
- Sequencing: The code running through the steps
- Iteration: the "while" statements
- Selection: the print statements?
Check: The selection is actually the "while j" and the iteration is the "while i"
Video 2 Hacks
-
a ⟵ 7
b ⟵ 1
c ⟵ 3
d ⟵ 4
a ⟵ b
b ⟵ c + d
d ⟵ b
- Answer: 1, 12, 3, 12 --> 1, 7, 3, 7
- Check: Not 12 it is 7, i did the math wrong sorry
-
hot ⟵ true
cold ⟵ false
cold ⟵ hot
hot ⟵ cold
- Asnwer: Both are true
-
dog ⟵ yes
cat ⟵ no
cat ⟵ dog
cow ⟵ pig
pig ⟵ owl
- display(cat)
- Asnwer: yes because dog is yes and since cat is dog, cat must also be yes in this case
-
cookie ⟵ 3
cake ⟵ 2
cookie ⟵ cake
donut ⟵ 5
chocolate ⟵ donut
caramel ⟵ 3
- display(donut + cake + cookie + chocolate + caramel)
- Answer: 17 looking at the code segmant its all the right values
-
Answer: num1 = 6, num2 = 11
-
Test 1
firstName <- "Bob" lastName <- "Smith" var <- substring(firstName, 1, 1) name <- concat(lastName, var) email <- concat(name, "@gmail.com") DISPLAY(email)
What would the result be?
Hint: var = "B" name = "SmithB"
Asnwer: Result would be "SmithB@gmail.com" for email based on the sequencing
- Test 2
word1 <- "computer" word2 <- "textbooks" length1 <- len(word1)/2 length2 <- len(word2)/3 first <- substring(word1, 2, len1) second <- substring(word2, len2+3, len2) newWord <- concat(first, second) DISPLAY(newWord)
Answer: since the length of "computer" is 8 then you divide it by two to get 4. Then for word2 it is 9/3 which is 3. This means it is the first 4 of "computer" besides 'c' and last 3 of "textbook" so the answer is "ompuook" for the result
Final Thoughts on lesson/reflection
- I really liked your presentation you can tell you guys put a lot of effort understanding what you were teaching and making the lesson super fun for everyone. I liked how the lessons were interactive and felt super fun and informative.
- The hacks were also super manageable but also challenging at times(like the last one)
- Good Job!!!!