Vocab

  • algorithms: set of instructions that can accomplish a specific task
  • Pseudocode: A blend of human language and coding format.
  • Strings: A string is a collection of characters. character can be anything from numbers, letters, spaces,
  • String concatenation: combining 2 or more strings to make a new strings in order to create a new string
  • Substrings: A substring is a part of and already existing string.

Mathematical Expressions and Strings

  • algorithms
    • set of instructions that can accomplish a specific task
    • Arithmetic operations in programming are performed in the same order as operations in mathematics
    • Three different types
      • sequence: Algorithms do tasks in the order of specification
      • selection: select two diff outcomes based on one decision
      • iteration: if a certain condition is proved true then a second step will be repeated
    • can be represented in two ways
      • Pseudocode: A blend of human language and coding format.
      • flow charts flowchart
  • Different way variables are stored
    • Numerical value stored in a variable
    • Value of another variable stored in a variable
    • Result of an operation stored in a variable
    • Result of a procedure call stored in a variable
score = 0   # 1
score = newScore    # 2
score = newScore + 2    # 3
avgScore = allscores(20, 60, 80)    # 4
  • Strings
    • A string is a collection of characters. character can be anything from numbers, letters, spaces, special symbols, etc.
    • len() to find the length of a string
    • lower() to convert to lowercase
    • len() returns the length of a string
  • String Concatenation
    • String concatenation is combining 2 or more strings to make a new strings in order to create a new string
    • concat() returns a string made up of the concatenated strings
    • concat("cookie","monster") returns cookiemonster
  • Substrings
    • A substring is a part of and already existing string.
    • substring() returns the characters from the string begining at the first position to the last. Ex: ("abcdefghijk", 2, 5) would print bced

HW

Noun = "Mr.Mortenson" 
Adjective = "handsome" 
Adjective2 = "Very" 
Verb = "is" 
abrev = Noun[0:6]
yoda = Adjective2 + " " + Adjective + " " + abrev + " " + Verb + "."
print(yoda)
Very handsome Mr.Mor is.
cookie = "choclate" 
cookie2 = "rasin" 
len1 = len(cookie) / 2 
len2 = len(cookie2) * 45 
vote1 = cookie + " vote " + str(len2) 
vote2 = cookie2 + " vote " + str(len1)
votes = vote1 +  " " + vote2
print(votes)
choclate vote 225 rasin vote 4.0