CSC111 Lab 9 2011

From dftwiki3
Revision as of 12:16, 2 November 2011 by Thiebaut (talk | contribs) (Working with Functions)
Jump to: navigation, search

--D. Thiebaut 13:15, 2 November 2011 (EDT)


Working with Functions

  • For this part, work in Idle or emacs and create the various functions this lab presents you, and test them in main().
  • For example, if you are asked to write a function that receives a string as parameter and prints it with a box around it, you could write something like this:



def boxIt( string ):
    noChars = len( s )
    print( "*" * ( 2 + noChars  + 2 ) )
    print( "| " + string + " |" )
    print( "*" * ( 2 + noChars + 2 ) )

def main():
    boxIt( "hello!" )
    boxIt( "This is a very long string!" )
    boxIt( "" ) # empty string 

main()



  • No need to add documentation for the code in this lab (or just in spots where you think you need to add markers for yourself)