CSC111 Exercises on Loops and Strings

From dftwiki3
Revision as of 16:40, 18 February 2010 by Thiebaut (talk | contribs) (Created page with '===Exercise 1=== What is output by the following code sections? for i in range( 5 ): for j in range( 3 ): print i+j, print for i in range( 3 ): pri…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Exercise 1

What is output by the following code sections?

for i in range( 5 ):
    for j in range( 3 ):
         print i+j,
    print 


for i in range( 3 ):
    print '-' * i


for i in range( 4 ):
     for j in range( i ):
          print j * '-'


Exercise 2

Write the code necessary to take the string "jan31feb28mar31apr30" and generate the following output from it:

jan 1 2 3 4 5 6 7 8 9 10 11 ... 27 28 29 30 31
feb 1 2 3 4 5 6 7 8 9 10 11 ... 27 28 
mar 1 2 3 4 5 6 7 8 9 10 11 ... 27 28 29 30 31
apr 1 2 3 4 5 6 7 8 9 10 11 ... 27 28 29 30


Exercise 3