Lab 3: Strings, Iteration, and Recursion

Logistics

  • Due: Thursday, May 28th no later than 5pm.
  • Submission instructions: upload your solution, entitled FirstName-LastName-Lab3.py to the BrightSpace Lab 3 Dropbox.
  • Deadline reminder: once this deadline passes, BrightSpace will no longer accept your Python submission and you will no longer be able to earn credit. Thus, if you are not able to fully complete the assignment, submit whatever you have before the deadline so that partial credit can be earned.

Learning outcomes

  • Gain experience manipulating strings.
  • Gain experience solving a problem using iteration.
  • Gain experience solving a problem using recursion.

Assignment

  • Download lab3.py and rename it according to the instructions above.
  • Rewrite the body of the length_built_in function to calculate and return the length of the paramter sentence using the built-in len function (see the documentation here). For example, if the sentence is "Montana State", the function should return 13.
  • Rewrite the body of the length_iterative function to compute the length of sentence using a loop. (Do not use the built-in length function.)
  • Rewrite the body of the length_recursive function to compute the length of sentence using recursion. (Do not use the built-in length function.)

Grading - 10 points

  • 3 points - the length_built_in function is implemented correctly.
  • 3 points - the length_iterative function is implemented correctly.
  • 4 points - the base case (2 points) and general case (2 points) of the recursive function are implemented correctly.

Grading turnaround

All labs graded with scores recorded in BrightSpace no later than lab time (2pm) the following day.