CSC111 Breaking-out-of-Loop Exercises

From dftwiki3
Revision as of 09:50, 17 November 2011 by Thiebaut (talk | contribs) (Problem 1 (to get the idea))
Jump to: navigation, search

--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.