What is an Algorithm

  • A set of instructions that can accomplish a specific task

3 different components

  • Sequencing - Algorithms do job in order of specification
  • Selection - Helps choose outcome based on a condition
  • Iteration - If a condition is true, the code will repeat

Algorithm Representations

  • Flowcharts
  • Pseudocode

Basic Operations

  • Subtraction represented by -
  • Addition represented by +
  • Multiplication represented by *
  • Division represented by /
  • Remainder represented by %
  • PEMDAS

Ways Variables are stored

  • Numerical values are stored
  • Value of another variable stored
  • Result of an operation stored
  • Result of a procedure stored

String

  • A string is a collection of characters
  • Characters can be anything from numbers, letters, spaces, special symbols, etc.
  • String concatenation is combining 2 strings into 1
  • A substring is a part of an already existing string
Num1 = 50
Num2 = Num1 % 9 + 15
Num3 = Num2 / Num1 + ( Num2 * 2 )
Num4 = Num3 + Num1 / 5 - 10
Result = Num4 - Num2

# In this block of code, Result will be equal to 20.4

Num1 = 10
Num2 = Num1 % 3 * 4
Num1 = Num2
Num3 = Num1 * 3
Result = Num3 % 2

# In this block of code, Result will be equal to 0

valueA = 4
valueB = 90
valueC = 17
valueB = valueC - valueA
valueA = valueA * 10
if valueB > 10:
    print(valueC)

# In this block of code, printing valueC will print 17

type = "curly"
color = "brown"
length = "short"
type = "straight"
hair = type + color + length
print(hair)

# In this block of code, printing hair will print the string "straightbrownshort"
Num1 = 10
Num2 = Num1 % 3 * 4
Num1 = Num2
Num3 = Num1 * 3
Result = Num3 % 2

# In this block of code, Result will be equal to 0

valueA = 4
valueB = 90
valueC = 17
valueB = valueC - valueA
valueA = valueA * 10
if valueB > 10:
    print(valueC)

# In this block of code, valueC will be equal to 17
# Noun = "Mr.Mortenson" 
# Adjective = "handsome" 
# Adjective2 = "Very" 
# Verb = "is" 
# abrev = subtring(Noun, 1, 7) 
# yoda = concat(Adjective2, " ", Adjective, " ", abrev, " ",Verb, ".") 
# print(yoda)

Noun = "Mr.Mortenson" 
Adjective = "handsome" 
Adjective2 = "Very" 
Verb = "is" 
abrev = Noun[0:7]
yoda = Adjective2 + " " + Adjective + " " + abrev + " " + Verb + "."
print(yoda)
Very handsome Mr.Mort is.
# cookie = "chocolate" 
# cookie2 = "raisin" 
# len1 = cookie / 2 
# len2 = cookie2 * 45 
# vote1 = (cookie, "vote", len2) 
# vote2 = (cookie2, "vote", len1) 
# votes = (concat(vote1, " ", vote2)) 
# print(votes)

cookie = "chocolate" 
cookie2 = "raisin" 
len1 = (len(cookie) / 2)
len2 = (len(cookie2) * 45)
vote1 = (cookie + " vote " + str(len2))
vote2 = (cookie2 + " vote " + str(len1))
print(vote1 +  " " + vote2)
chocolate vote 270 raisin vote 4.5