Class 29 — Monday, November 1

Listing

To be, not to be — That is the question I ask – The answer, to be


Look both ways


Agenda


To do


Pillow download


Parameter passing downloads


Optional parameters downloads


Module self-testing downloads


Remembering the past

# 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



Puzzle me this

# program my.py | # module gosh.py

import gosh | def f( x ) :

nbrs = [ 3, 1, 4 ] | x = [ 0, 0, 0 ]

gosh.f( nbrs ) | return

print( nbrs ) |

[ 3, 1, 4 ]

[ 0, 0, 0 ]



Now what's happening

# 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 ]



Optional parameters

print( "hurry", end=" " )

print( "up", end=" " )

Produces

hurry up

def chant( msg='Wahoo Wah', n=3 ) :

  for i in range( 0, n ) :

  print( msg )

  return

alma.chant()

...

alma.chant( msg='Hip hip hooray!' )

...

alma.chant( n=5 )

...

alma.chant( 'We are CS 1112', 1 )

chanting with no parameters

Wahoo Wah

Wahoo Wah

Wahoo Wah

chanting with message parameter set

Hip hip hooray!

Hip hip hooray!

Hip hip hooray!

chanting with number of repetitions set

Wahoo Wah

Wahoo Wah

Wahoo Wah

Wahoo Wah

Wahoo Wah

chanting with arguments for message and repetition parameters

We are CS 1112


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.py — homework 24

Function rotate( x )


Function rotate_k_times( x, k )


Function common( x, y )


Slide show