Big idea 3!
Lesson on Big Idea 3 which includes expressions, strings, psuedocode, and more
Vocab: fill in the blanks
the symbol for exponent is *
the symbol for addition is +
the symbol for subtraction is -
the symbol for multiplication is
the symbol for division is /
the symbol for modulus is % - does remainder
an algorithm is sequence of steps that does a specific task
sequencing is an order of steps. selection is doing a specific action based on a condition (like an if statement). iteration is a loop (for, while) just repeats
Sequencing Practice: the code below does not follow the intended steps below. change the code so that it does so.
- divide value1 by 10(value1 = 5)
- multiply 2 from the result of the step 1
- subtract 4 from the result of the step 2
- print the result of step 3
value1 = 5
value2 = value1 / 10
value3 = value2 * 2
value4 = value3 - 4
print(value4)
Selection/Iteration Practice: Create a function to print ONLY the numbers of numlist that are divisble by 3.
Hint: use the MOD operator (a % b) to find the remainder when a is divided by b.
numlist = "3","4","9","76","891","999"
for num in numlist:
if int(num) % 3 == 0:
print(str(num) + " is divisible by 3")
continue
else:
continue
Homework/Binary Adaptation: Create a python function that will convert a decimal number 1-255 to binary using mathematical operations and powers of 2. Challenge: add frontend with javascript or html.
def convert(dec):
bin = ""
i = 20
while i >= 0:
if dec % (2**i) == dec:
bin = bin + "0"
i -= 1
else:
bin = bin + "1"
dec -= 2**i
i -= 1
print(bin)
convert(1)
Vocab: fill in the blanks using the video
Index is a number representing a position, like a character's position in a string or a string's position in a list.
Concatenation is combining two strings
Length is how many characters
A substring is a part of a string (certain characters of a string)
index: the position of a character in a string or a string in a list. psuedocode starts with one but most start with 0
What is psuedocode?
Pseudocode is writing out a program in plain language with keywords that are used to refer to common coding concepts.
Can you think of some benefits of using pseudocode prior to writing out the actual code?
- Choose an everyday activity
- Imagine that you are providing instructions for this activity to a person who has never done it before
- Challenge someone to do the steps you wrote out
MY EXAMPLE:
SANDWICH
Take two slices of bread out of a bread bag take lettuce, tomatoes, and cheese out of the fridge take mayo out of the fridge put the lettuce, tomatoes, and mayo on a plate but do not mix them. cut into pieces the size of the bread. place one piece of bread place tomatoes on the piece place lettuce on the piece on top of the tomatoes place cheese on the piece on top of the lettuce pour a reasonable amount of mayo on top of the cheese on the piece put the other slice of bread on top eat it
Ex. Brushing Teeth
- Pick up your toothbrush
- Rinse toothbrush
- Pick up toothpaste
- Place toothpaste on the toothbrush
- Rinse toothbrush again
- Brush teeth in a circular motion
- Spit
- Wash mouth
- Rinse toothbrush
- You have brushed your teeth!
string = "hellobye"
print(len(string))
print(string[0:5])
print(string[5:8])
Concatenation Practice: combine string1 and string2 to make string3, then print string3.
string1 = "computer"
string2 = " "
string3 = "science"
string4 = string1 + string2 + string3
print(string4)
Homework/List Adaptation: create a function that prints the name of each string in the list and the string's length. Challenge: add frontend with javascript or html.
names = ["yppee","yippee","doubleyippee","yip"]
def length(list):
for name in names:
print(name + ": " + str(len(name)))
length(names)
Stuck?
- Check out what we did.