# flow.py # Walker M. White (wmw2) # September 9, 2012 """Trace statements illustrating control statment flow Trace statements are just print statements that tell us where we are in the code. They are distinct from a watch, which tells us the current contents of a variable.""" import point def max2(x,y): """Returns: max of x, y Shows of flow of if-else""" # Put max of x, y in z print 'before if' if x > y: print 'if x>y' # trace z = x print 'z is '+`z` # watch else: print 'else x<=y' z = y print 'z is '+`z` # watch print 'after if' return z def max3(x,y,z): """Returns: max of x, y, z Shows of flow of if-elif-else""" # Put max of x, y, z in w print 'before if' if x > y and x > z: print 'if x>y and x>z' # trace w = x print 'w is '+`w` # watch elif y > z: print 'elif y>z and y>=x' # trace w = y print 'w is '+`w` # watch else: print 'else z>=x and z>=y' w = z print 'w is '+`w` # watch print 'after if' return w def shift(p): """Shifts the values of p to the left. This shows off tracing and watches""" print 'Start shift()' # trace p.x = p.y print 'p.x is '+`p.x` # watch p.y = p.z print 'p.y is '+`p.y` # watch p.z = p.x print 'p.z is '+`p.z` # watch print 'End shift()' # trace def proxy_shift(p): """Calls shift(p) This shows off tracing of helper functions""" print 'Start proxy_shift()' # trace shift(p) print 'End proxy_shift()' # trace