Lab 3: Strings, Iteration, and Recursion

Logistics

  • Due: Thursday, June 13th 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 count_built_in function to calculate and return the number of "z"’s in the paramter sentence using the built-in count method (see the documentation here). For example, if the sentence is "Jazz music played during the movie Zootopia", the function should return 3.
  • Rewrite the body of the count_iterative function to count the number of "z’s in sentence using a loop. (Do not use the built-in count method.)
  • Rewrite the body of the count_recursive function to count the number of "z"’s in sentence using recursion. (Do not use the built-in count method.)

Grading - 10 points

  • 3 points - the count_built_in function is implemented correctly.
  • 3 points - the count_iterative function is implemented correctly.
  • 4 points - the base case (2 points) and 2 general cases (1 point each) 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.