Lesson One

- core of computer science
- breaking down problem into smaller parts, that can be precisely and mechanically described and used to solve each piece
- steps that can be executed by computers

- universal machine
- can do anything can a write a program for
- program needs to be precise series of steps

- python is an interpreter, meaning it runs programs in a language that the computer understands

Language Ambiguity

- natural languages are inherently ambiguous
- computer must interpret programs without ambiguity
- must be precise, whereas words can be interpreted differently
- natural languages are verbose


- python has many strings, much like English
- in English, people will still understand language

Bachus-Naur Form:
- purpose is to describe language in way that is precise

-> replacement
sentence -> subject verb object
subject -> noun
object -> noun
verb -> eat
verb -> like
noun -> like
noun -> I
noun -> python
noun -> cookies

Replacement language:
- describes large language rules with small number of rules and precision

Python expressions:
- very precise: must match grammar exactly

Python grammar for arithmetic expressions:
expression -> expression operator expression
expression -> number
operator -> +
operator -> *
number -> 0,1,…
expression -> (expression)


Assignment statement:
name = expression
speed_of_light = 299792458

- variables usually don't start with capital letters
= means assignment, rather than equation (more like an arrow)


A sequence of characters surrounded by quotes
+_ -> concatenation of the two strings results in a new string pasting the two strings together
e.g. 'I am a string' or “I'm a string” (with double quotes)

Indexing Strings:
- can subtract sub-sequences from the strings
- characters of strings are indexed starting from zero

e.g. 'udacity' [0] -> u, [1] -> d etc

name = 'Dave'
name[0] -> 'D'
name[-1] -> 'e'

Selecting sub-sequences:
-string that is a subsequence of the characters in the string, starting from position start and ending with position stop -1


Finding substrings in big strings:
- find is a method (build in procedure)

- output is position in string where that string occurs
- case sensitive

- number that gives first position in search string, where the largest string appears [at or after ]

Lesson Two

Procedural Abstraction (motivating procedures)

- abstract to make procedure things happening over and over
- things that change, are inputs
- output is the output

- parameters = inputs - ,

4 spaces indented

- body of procedure, code that runs

Using Procedures:
- inputs sometimes called operands or arguments

Defining Procedures:
def rest_of_string(s):
return s[1:]
print rest_of_string('audacity')


def square(a):
     return a * a

print square(5)

Equality Comparisons

< > <=

output is a boolean value: true, or false

print 2 < 3


For equality comparisons use ==



def absolute(x):

if x<0:

x = -x

return x

If block is false, it doesn't execute