Saturday lecture notes

Friday review

math

type()

variables

strings

booleans

if/elif/else

functions

Lists

purpose

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

initialization

len() review

accessing elements

adding elements

changing elements

slicing lists

strings are like lists

loops and more flow control

for loops

if statements inside for loops

nested for loops

range()

while loops

infinite loops

if statements inside while loops

break

raw_input()

dictionaries

purpose

Think of a phone book!

initialization

accessing elements

adding elements

changing elements

keys() and values()

modules

purpose

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

builtins

imports

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

Putting it all together

capitals.py, a quiz game