knerr cs21 notes...

back to schedule

WEEK01: intro to python, unix, cs21, interviews with students
---------------------------------------------------------------
 W: data types, variables, input/output, simple functions

Announcements:
  - Lab 0
  - Lab 1
  - 15-min interview with me
  - ninja session tonight
  - need to know vim for Friday's class
  - did you get the test email?
  - don't forget using unix
  - try update21, handin21?
  - prox tags??
  - how to log out!!

DATA TYPES: string, int, float
  - what they are:
        strings: "hello" "jeff" "This is FUN!!"
        integers: 5 360 -21
        floating point numbers: 3.14159  -6.2  800.0
  - things you can do with them (+, -, *, etc)
  - type('a'), type(21), type(3.141)
  - simple functions:
       type('hello') 
       int(5.0)
       int('5')
       float(5)
       str(5)  
       int(3.141)

VARIABLES: place to store a value
  - rules for names
  - why do we use them?
  - examples:
       x = 5
       y = "hello"
       name = "Jeff Knerr"
       z = 3.141 * x

INPUT vs RAWINPUT
  - input, do something, output
  - input     (set equal to)
      x = input("please enter a number: ")
  - raw_input (string)
      x = raw_input("please enter your name: ")

FUNCTIONS:
  - def
  - indent

def hb():
  print "happy birthday to you!!"

  - indent
  - why use them
  - happy birthday song example

def song():
  hb()
  hb()
  print "happy birthday dear jeff"
  hb()

**--** write a program to do this:

please enter your name and the year you were born...
your full name: jeff knerr
year you were born: 1965

Hello, jeff knerr
You are 44 years old!


  - think first!!! (don't just start typing)
  - write it out on paper first!! (don't just start typing)
  - say hello to your neighbor first!! (don't just start typing)
  - talk it over with your neighbor first!! (don't just start typing)


IF YOU HAVE TIME:
  - what happens when you enter nonsense values for your
    name and age (ex: enter your age for your name and vice versa)
  - try using vim to enter your program in a hello.py file
  - what happens when you try these?
  >>> 4 + 5 * 2
  >>> (4 + 5) * 2
  >>> 5 * 2 + 4
  >>> 5 * (2 + 4)

IF YOU DON'T HAVE TIME:
  - you are welcome to look at or copy my inclass programs:

        cp  ~jk/inclass/hello.py  hello.py
        cp  ~jk/inclass/hellomain.py  hellomain.py