Saturday lecture notes

Friday review

math

In [ ]:
 

type()

In [ ]:
 

variables

In [ ]:
 

strings

In [ ]:
 

booleans

In [ ]:
 

if/elif/else

In [ ]:
 

functions

In [ ]:
 

Lists

In [ ]:
 

purpose

Conveniently handle bunches of data that will all need to be treated together!

initialization

In [ ]:
 

len() review

In [ ]:
 

accessing elements

In [ ]:
 

adding elements

In [ ]:
 

changing elements

In [ ]:
 

slicing lists

In [ ]:
 

strings are like lists

In [ ]:
 

loops and more flow control

for loops

In [ ]:
 

if statements inside for loops

In [ ]:
 

nested for loops

In [ ]:
 

range()

In [ ]:
 

while loops

In [ ]:
 

infinite loops

In [ ]:
 

if statements inside while loops

In [ ]:
 

break

In [ ]:
 

raw_input()

In [ ]:
 

dictionaries

purpose

Think of a phone book!

initialization

In [ ]:
 

accessing elements

In [ ]:
 

adding elements

In [ ]:
 

changing elements

In [ ]:
 

keys() and values()

In [ ]:
 

modules

purpose

  • Don't write it twice!
  • Don't write it at all!

builtins

In [ ]:
 

imports

In [ ]:
import random
In [ ]:
random.randint(1, 100)
In [ ]:
random.choice([2, 8, 'twelve'])

Putting it all together

capitals.py, a quiz game