# lec07_pythontutorized.py # Lillian Lee (LJL2) and Steve Marschner (SRM2) # Feb 13, 2014 """Simplified version of lecture 07, converted into snippets you can paste into Python Tutor. It doesn't import any modules After you paste a snippet in, hit the "Visualize Execution" button to step through the code. Use the "Execute code using" setting "use text labels for references" instead of "draw references using arrows". Python Tutor is at http://www.pythontutor.com/visualize.html. """ #### begin snippet lt_speed = 3e8 #speed o' light def v_p_try1(): """Changes lt_speed, supposedly""" lt_speed = 42.0 v_p_try1() #### end snippet #### begin snippet lt_speed = 3e8 #speed o' light def v_p_try2(new): """Changes lt_speed to new, supposedly""" lt_speed = new v_p_try2(42.0) #### end snippet #### begin snippet lt_speed = 3e8 #speed o' light def v_p_try3(lt_speed): """Changes lt_speed to 42.0, supposedly""" lt_speed = 42.0 v_p_try3(lt_speed) #### end snippet #### begin snippet lt_speed = 3e8 #speed o' light def boring(new): """Returns new""" return new lt_speed = boring(-lt_speed) ### end snippet #### begin snippet class Anum(object): """dummy class to have really simple objects with a single attribute, x, a float.""" def __init__(self, x): """Initializer: an Anum with x value """ self.x = x def change(an): """Change Anum an's x value to its square. Precond: an is an Anum""" an.x = an.x**2 a = Anum(3) a_new = change(a) # nothing should get stored in a_new, but a's x should change #### end snippet