# module my_utils2 # # this module contains a few short utilities # # started by e.bonakdarian nov 2010 # # You will not be using any for-loops in any of the functions. This # is only to help you get more practice with while loops - ordinarly # these are the type of cases were we would use for-loops. However, # for this assignment, our goal is to become super-comfortable with # while loops. # # Please note that these functions are very *similar* in functionality # as those in for_loops.py, but there are some important differences. Be # sure you read the function specs fully and carefully, you are *not* # simply replacing for-loops with while-loops (though that is a major # part of it. # # for COMP 101, to be finished by students # ######################################################################### def bike_banner(): # displays a fancy bicycle banner print '----------------------------------------------------------' print ' __o' print ' _`\<,_' print '(*)/ (*)' print 'YOUR NAME HERE' ########## NOTE print '----------------------------------------------------------' ######################################################################### def simple_banner(): # displays a banner print '----------------------------------------------------------' print 'YOUR NAME HERE' ########## NOTE print '----------------------------------------------------------' ######################################################################### def printStarLines_Ln(number, kar): # prints a single line made up of 'number' of 'kars' # *followed by a newline* (i.e., the cursor moves to the next line. # # You have to use a while loop pass ######################################################################### def printStarLines(number, kar): # prints a single line made up of 'number' of 'kars'. # NOTE :there is *NO* newline at the end of this single # line you are printing. # # hint: there is only a one-line difference between this # function and printStarLines_LN # # You have to use a while loop pass ######################################################################### def box(width): # print a 'box' of height 5 and width 'width' of 'x' characters # # Note that you may be able to use one of the printStarLines methods # this module to help you with this code # # You have to use a while loop pass ######################################################################### def box2(height, width): # print a 'box' of height 'height' and width 'width' of '*' chars # Note that you may be able to use one of the printStarLines methods # this module to help you with this code # # You have to use a while loop pass ######################################################################### def square(dim): # print a 'square' size dim * dim, i.e. height 'dim' and width 'dim' # of '.' characters # # Note that you may be able to use one of the printStarLines methods # this module to help you with this code # # You have to use a while loop pass ######################################################################### # # ********* no changes required below here (unless you want to) ********* # ######################################################################### def test_utils2(): # this function is used to test the functions in this # module. Ordinarily this would not be called if the # module was imported by some other code. # # You don't have to modify this code unless you want to. # print '=============================================' print ' *** Output of test_utils2 function ***' print '=============================================' print print print 'fancy banner first' bike_banner() print print 'simple banner now:' simple_banner() print 'testing printStarLines()' # this should print AAAAA @@@@@ # note, there are 5 blanks printStarLines(5, 'A') printStarLines(5, ' ') printStarLines(5, '@') print '\n\n\n' # a few blank lines print 'testing printStarLines_Ln()' # this should print # AAAAA # # @@@@@ # note, there are 5 blanks in the "middle line" printStarLines_Ln(5, 'A') printStarLines_Ln(5, ' ') printStarLines_Ln(5, '@') # see output provided with assignment print '\n\ntesting box(3)' box(3) # height 5, width 3 print '\n\ntesting box(15)' box(15) # height 5, width 15 print '\n\ntesting box2(5, 10)' print '-------------------' box2(5, 10) # height 5, width 10 print '\n\ntesting box2(5, 20)' print '-------------------' box2(5, 20) # height 5, width 20 print '\n\ntesting box2(5, 5)' print '-------------------' box2(5, 5) # height 5, width 5 print '\n\ntesting box2(6, 3)' print '-------------------' box2(6, 3) # height 6, width 3 for i in range(1, 8, 2): print '\n\ntesting square with parameter %d' %i print '-------------------' square(i) # 1, 3, 5, 7 # you may want to add more calls of your own if you have some # additional test cases you want to try out. ######################################################################### if __name__ == '__main__': # this code can be used to test the functions # in this module # # if the module is imported, this code will not # be run -- pretty cool mechanism. # test_utils2() raw_input('\n to exit')