# 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 tuple3d 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 '+str(z) # watch else: print 'else x<=y' z = y print 'z is '+str(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 '+str(w) # watch elif y > z: print 'elif y>z and y>=x' # trace w = y print 'w is '+str(w) # watch else: print 'else z>=x and z>=y' w = z print 'w is '+str(w) # watch print 'after if' return w def cycle_left(p): """Cycles the values of p to the left. This shows off tracing and watches""" print 'Start cycle_left()' # trace p.x = p.y print 'p.x is '+str(p.x) # watch p.y = p.z print 'p.y is '+str(p.y) # watch p.z = p.x print 'p.z is '+str(p.z) # watch print 'End cycle_left()' # 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