Difference between revisions of "CSC111 Breaking-out-of-Loop Exercises"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- ==Problem 1 (to get the idea)== * Given a list of lines L, shown below, write a program that generate the list of the line numbers for lines containing words starti...")
 
(Problem 1 (to get the idea))
Line 6: Line 6:
 
* Given a list of lines L, shown below, write a program that generate the list of the line numbers for lines containing words starting with 'a' and ending with 'z'.
 
* Given a list of lines L, shown below, write a program that generate the list of the line numbers for lines containing words starting with 'a' and ending with 'z'.
  
  L = [ "------- --------- -------- --- - --------- ---------",         # line 0
+
  L = [ "------- --------- -------- --- - --------- ---------",           # line 0
 
         "------- ---------- a----z -------- -- --------- --------",      # line 1
 
         "------- ---------- a----z -------- -- --------- --------",      # line 1
 
         "------- ---------- ------ -------- -- --------- --------",      # line 2
 
         "------- ---------- ------ -------- -- --------- --------",      # line 2

Revision as of 09:50, 17 November 2011

--D. Thiebaut 09:50, 17 November 2011 (EST)


Problem 1 (to get the idea)

  • Given a list of lines L, shown below, write a program that generate the list of the line numbers for lines containing words starting with 'a' and ending with 'z'.
L = [ "------- --------- -------- --- - --------- ---------",           # line 0
       "------- ---------- a----z -------- -- --------- --------",      # line 1
       "------- ---------- ------ -------- -- --------- --------",      # line 2
       "------- ---------- ------ -------- -- --------- --------",      # line 3
       "------- ---------- ------ -------- az --------- --------",      # line 4
       "------- ---------- ------ -------- -- --------- --------" ]     # line 5
  • For the example above, the result would be a list newL = [ 1, 4 ].

Problem 2 (the real problem)

  • Same idea, but we want to get the first line that contains such a word.