3.3 and 3.4 Mathematical Expressions/Strings
HW 2
- Algorithms are a finite set of instructions that accomplish a task. it has three parts, sequence, selection, and iteration
- A sequence is the order of how to do something to achieve a result, similarly to how you follow the instructions from a teacher.
- A selection allows an algorithm to make a decision based on if a condition is met, an example of this is when your car is out of fuel, you go to the gas station to fill your car, but if your car is full you wouldn't go to the gas station.
- An iteration is a loop and doing something again until a condition is met, like you put away your computer when you are finished with your work.
- Arithmetic uses addition, subtraction, division, multiplication, and modulus operator
- Addition: a+b
- Subtraction: a-b
- Multiplication: a*b
- Division: a/b
- Modulus: a MOD b
- (a and b can be string or number)
- A string concatenation connects two or more string end-to-end to make a new string
- Len() gives the character number
- strings are variables and can be joined together through the print() command to make a statement
Hacks
1
- Sequence
- Sequence
- Selection
- Iteration/Selection
- Sequence
- The sequences are just the items and steps in order. The first set is to set item to a number and then get next number in the list.
- The slection is number three and number 4 because it is making a decion based on and input and giving a different output depending on what the input was.
- The iteration is 4 because it is redirecting the code also known as looping. ## Crossword
- 1) Iteration
- 2) Selection
- 3) Sequence ## 2
num1 = 5
num2 = num1 * 3
num3 = num2 / num1 * (9 % 2) * 4
result = (num3 % num1 + num2) % num3 * 3 / 5
5 X 3 = 15/5= 3 9/2 leaves remainder of 1 1 X 4 X 3 = 12 12 % 5 = 2 + 12 = 15 17 % 12 = 5 5 X 3= 15 15/5= 3