An Intro to
Programming
with Python

Fall 2006
course
navigation

oct 6

asides

this is code

functions

decisions

If no other questions, start talking about material in chap 7 and 8
if x < 7 : print "x is small" else : print "x is big"
Draw as flow chart.
The "x < 7" is the part I want to talk about (pg 250 etc) in text.
We're now going to have programs that 'branch', which means that different things can happen. The decision point is a fork in the road, and which one happens is nearly always a True/False choice using what are called 'booleans'.

what is 'truth' ?

math : binary (two things) operations : integer <operation> integer ==> integer 1 + 2 ===> 3 unary (one thing) operations : <operation> integer ===> integer - (1) ===> (-1) 5! ===> 120 (factorial logic : 'bool' in python is a 'boolean' variable: True or False have both binary and unary operations with their own algebra not ( x or not y ) and (not y or z) boolean operations: not, and, or values: True, False also in common use : if a then b sometimes written a implies b which in itself can also be True or False comparisons on strings and numbers that give booleans : <, > , <=, !=, is
Do some examples at the python command line.
Discuss definitions of 'and', 'or' in logic.
Lewis Carroll's 'Symbolic Logic' e.g. http://home.earthlink.net/~lfdean/carroll/puzzles/logic.html (1) Every one who is sane can do Logic; (2) No lunatics are fit to serve on a jury; (3) None of your sons can do Logic. What conclusion can be drawn? Use a = able to do Logic b = fit to serve on a jury c = sane d = your sons Express each line as a boolean expression. Use the rules of boolean algebra to draw a short conclusion. Answer: None of your sons is fit to serve on a jury.
http://cs.marlboro.edu/ courses/ fall2006/python/ notes/ oct_6
last modified Friday October 6 2006 10:44 am EDT