3.3/3.4 Mathematical Expressions/Strings

Notes

  • 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

Hack 1

  1. Sequence
  2. Sequence
  3. Selection
  4. Iteration/Selection
  5. 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.

Hack 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

Crossword

  1. Iteration
  2. Selection
  3. Sequence

Hack 3

Strings Quiz

Friday Presentation Script

  • Algorithm: Algorithm is the overall flow of the code. It is the end tasks that is achived through sequence, selection, and iteration.
  • Sequence: A sequence is the order of the algoritm
  • Selection: A selection is a decesion the algorithm makes based on other conditions.
  • Iteration: Its a loop. It repeats a series of code until a certain condition is met.
  • Arithmetic: The math of code: addition, subtraction, multipication, and divsion
age = 16
permit = True
# The whole entire block of code is an Algorithm. The order of this code is a sequence

#When they are under age they wait a year until they are over.
# This is a while loop as well as an iteration. It loops back around when the condition isn't met
while age <= 15:
    age = age + 1
    print(age)
    # These are conditionals and nested conditionals
    # This is a selction 
if age >= 16:
    # Here is a boolean expression
    if permit == True:
        print("Here is your Drivers License")
        #if they don't have enough money they will say they are poor
    else:
        print("You have not completed your permit course")
Here is your Drivers License
numbers = 0 
n = 1
while numbers < 80:
    numbers = 3+(n-1)*13
    n = n + 1
    print(numbers)
3
16
29
42
55
68
81