What is an algorithm?

  • A set of instructions that accomplish a specific task
  • They have three components:
    • Sequencing: tasks in the order of specification
    • Selections: Choosing different outcomes based on a situation and a decision
    • Iteration: If something is true, repeat it
  • Algorithms can be represented by Flowcharts and Pseudocode

Arithmetic Operations

  • Addition: (+)
  • Subtraction: (-)
  • Multiplication (*)
  • Division: (/)
  • Getting the remainder: (%)

Order of Operations

  • Operations in parentheses should be done first
  • " * " and " / " before " + " and " - "
  • " % " are similar to " * " and " / "

Variables

  • Sequence is very important
  • Tracking variables is commonly used in the AP Exams and is an important thing

What is a string?

  • A collection of characters
  • len() will find the length of a list
  • lower() to covert list to lowercase
  • concat() combines two strings

Hacks/Homework

Num1 = 50
Num2 = Num1 % 9 + 15
Num3 = Num2 / Num1 + ( Num2 * 2 )
Num4 = Num3 + Num1 / 5 - 10
Result = Num4 - Num2


# 50/9 = 45 R=5; 5 + 15 = 20 = num2
# 2/5 + 40 = 40.4 = num 3
# 40.4 + (50/5) - 10 = 40.4 + 10 - 10 = 40.4 =  num4 
# Result = 40.4 - 20 = 20.4
# Checking answers

print(Num1)
print(Num2)
print(Num3)
print(Num4)
print(Result)
50
20
40.4
40.4
20.4
Num1 = 10
Num2 = Num1 % 3 * 4
Num1 = Num2
Num3 = Num1 * 3
Result = Num3 % 2

# num1 = 4
# 10/3 = 1 x 4 = 4 = num2
# 4 x 3 = 12 = num3
# 12/2 = 0 = Result 
# Checking answers

print(Num1)
print(Num2)
print(Num3)
print(Result)
4
4
12
0
valueA = 4
valueB = 90
valueC = 17
valueB = valueC - valueA
valueA = valueA * 10
if valueB > 10:
    print(valueC)

# 17 - 4 = 13 
# valueA = 40
# code will print 17 since 13>10
# Checking answers
17
type = "curly"
color = "brown"
length = "short"
type = "straight"
hair = type + color + length
print(hair)

# Will print straightbrownshort
# Checking answers
straightbrownshort
Noun = "Mr.Mortenson" 
Adjective = "handsome" 
Adjective2 = "Very" 
Verb = "is" 
abrev = Noun[0:7] 
yoda = (Adjective2 + " " + Adjective + " " + abrev + " " + Verb + ".") 
print(yoda)

# Prediction: Very handsome Mr.Mort is
Very handsome Mr.Mort is.
cookie = "chocolate" 
cookie2 = "rasin" 
len1 = len(cookie) / 2 
len2 = len(cookie2) * 45 
vote1 = (cookie + " cookie votes: " + str(len1)) # creating a string for choco cookie
vote2 = (cookie2 + " cookie votes: " + str(len2)) # creating a string for rasin cookie
votes = (vote1 + "           " + vote2) # displaying votes for them 
print(votes)

# chocolate is 9 characters long 9/2 = 4.5 = chocolate cookie votes
# rasin is 5 characters long 5 * 45 = 225 = rasin cookie votes
chocolate cookie votes: 4.5           rasin cookie votes: 225