Algorithm

Selection helps choose between 2 different algorithms Sequencing Iteration

Flowcharts use shapes and arrows to represent the steps of an algorithm.

Arithmetic Operations

Addition Represented by "+" Subtraction Represented by "-" Division Represented by "/" Multiplication Represented by "*" Modulus Represented by "%"

Order of operations is the same, uses PEMDAS.

Variables

Ways to Store Data

  1. Numerical value stored in a cariable

Changing the order of the steps changes the overall outcome, since every time the value assigned to a variable is changed, it changes from the previous value which was assigned to the same variable.

String

A string is a collection of characters, and anything can be any symbol

Examples of python len() finds the length of a string lower() to convert to lowercase

String concatenation is combining 2 or more strings to make a new strings in order to create a new string

Num1 = 50
Num2 = Num1 % 9 + 15                    # num2 = 20
Num3 = Num2 / Num1 + ( Num2 * 2 )       # num3 = 20/50 + 40 = 40.4
Num4 = Num3 + Num1 / 5 - 10             # num4 = 40.4 + 10 - 10 = 40.4
Result = Num4 - Num2                    # Result = 40.4 - 20 = 20.4

# Hacks Part 1 Problem 2
Num1 = 10
Num2 = Num1 % 3 * 4                     # num2 = 1 * 4 = 4
Num1 = Num2                             # num1 = 4
Num3 = Num1 * 3                         # num3 = 4 * 3 = 12
Result = Num3 % 2                       # Result = 0

# Hacks Part 1 Problem 3
valueA = 4
valueB = 90
valueC = 17
valueB = valueC - valueA                # valueB = 17 - 4 = 13
valueA = valueA * 10                    # valueA = 4 * 10 = 40
if valueB > 10:                         # valueB is 13, which is greater than 10
    print(valueC)                       # This will print 17
17
type = "curly"
color = "brown"
length = "short"
type = "straight"
hair = type + color + length

print(hair)
cookie = "chocolate" 
cookie2 = "raisin" 
len1 = (len(cookie) / 2)
len2 = (len(cookie2) * 45)
vote1 = (cookie + " vote " + str(len2))
vote2 = (cookie2 + " vote " + str(len1))
print(vote1 +  "\n" + vote2)
chocolate vote 270
raisin vote 4.5
Noun = "Mr.Mortenson" 
Adjective = "handsome" 
Adjective2 = "Very" 
Verb = "is" 
abrev = Noun[:7]
yoda = Adjective2 + " " + Adjective + " " + abrev + " " + Verb + "."
print(yoda)
Very handsome Mr.Mort is.