Class 29 — Monday April 12

Moving on

Working Together – On a cautionary tale – New understandings


Look both ways


Parameter passing downloads


Module self-testing downloads


Next homework


Agenda


To do


What the heck happens (PDF, slide show)

# program cautionary.py | # module tale.py

import tale | def f( x, y ) :

city1 = 'London' | rmbr = x

city2 = 'Paris' | x = y

tale.f( city1, city2 ) | y = rmbr

print( city1, city2 ) | return

London Paris

Paris London



Now what the heck happens

# program up.py | # module date.py

import date | def f( x ) :

nbrs = [ 3, 1, 4 ] | n = len( x )

date.f( nbrs ) | for i in range( 0, n ) :

print( nbrs ) | x[ i ] = 0

  | return

[ 3, 1, 4 ]

[ 0, 0, 0 ]



Tester statement if ( __name__ == '__main__' )

if ( __name__ == '__main__' ): # __name__ is a built in python variable.

  import abet # it is set to the string '__main__' if

  # you are running the file as a program

  # it is set to the name of the file if

  # the file is being imported

  abet.test_rotate()

  abet.test_rotate_k_times()

  abet.test_common()



Module for next class aid.pyhomework 25

Function rotate( x )


Function rotate_k_times( x, k )


Function common( x, y )


Slide show

 


  🦆 © 2022 Jim Cohoon   Resources from previous semesters are available.