Difference between revisions of "CSC111 Lab 9 2011"
(Created page with "--~~~~ ---- =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()'''. *...") |
(→Working with Functions) |
||
Line 12: | Line 12: | ||
def boxIt( string ): | def boxIt( string ): | ||
noChars = len( s ) | noChars = len( s ) | ||
− | print( "*" * ( noChars | + | print( "*" * ( 2 + noChars + 2 ) ) |
− | print( "| | + | print( "| " + string + " |" ) |
− | print( "*" * ( noChars | + | print( "*" * ( 2 + noChars + 2 ) ) |
def main(): | def main(): |
Revision as of 12:16, 2 November 2011
--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)