Lab 4: Strings, Loops and Recursion
Logistics
- Due: Tuesday, September 19th no later than 11:59 p.m.
- Partner Information:
Everyone is required
to complete this assignment with a partner
who is in your same lab section.
Your lab TA will help you find a partner at the
start of your lab period if you don't already know who
your partner will be.
- Submission Instructions: Upload your
solution, entitled
YourFirstName-YourLastName-PartnerFirstName-PartnerLastName-Lab4.py
to the BrightSpace Lab 4 Dropbox. Note:
Only one person needs to submit a solution. If you both submit a solution,
the submission that will be graded is the one from the partner whose last
name comes alphabetically first.
- 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 with strings.
- Gain experience with loops.
- Gain experience with recursion.
Assignment
- Download lab4.py and rename
it according to the instructions above.
- Modify the program by adding the four missing functions.
The functions are described in the grading section below.
- If the missing functions
are implemented correctly, this output
will appear when the user enters how now brown cow for the
first string and ow for the second string. Note: Your
solution should work for any pair of strings.
Grading - 10 points
Note: For this lab, you are required to work with a partner and submit
a joint solution. If you submit a solution without a partner,
3 points will be deducted.
- 4 points - A function named concatenation_loop is
implemented that has two string parameters. The function must
return the concatenation of the two strings using an appropriate loop.
You may use the built-in concatenation operator (+) to concatenate
a string and a character. However, you may not use it to concatenate
two strings.
- 1 point - A function named concatenation_recursion is
implemented that has two string parameters. The function must
return the concatenation of the two strings using recursion.
You may use the built-in concatenation operator (+) to concatenate
a string and a character. However, you may not use it to concatenate
two strings. Do not use any loops in the solution.
- 4 points - A function named occurrences_loop is
implemented that has two string parameters. The function must
return the number of times that the second string parameter appears
in the first using an appropriate loop. The built-in count function
may not be used.
- 1 point - A function named occurrences_recursion is
implemented that has two string parameters. The function must
return the number of times that the second string parameter appears
in the first using recursion. Neither the built-in count function
nor any loops may be used.
If Time Remains
If you want to work with a partner on Program 2 (due 9/29), use
this time to identify a partner or ask your lab TA to help you find
someone. Note: For the vast majority of computing jobs and internships,
the ability to work with one or more teammates is a crucial skill!