Intro to Python Programming_Mod 3.docx
Intro to Python Programming_Mod 3.docx
This assignment is designed to give you practice writing code and applying lessons and
topics for the current module.
● Strings
● Lists
● Sets
● Tuples
The Assignment
In this assignment, you will implement some functions related to strings, lists, sets and tuples.
Each function has been defined for you, but without the code. See the docstring in each
function for instructions on what the function is supposed to do and how to write the code. It
should be clear enough. In some cases, we have provided hints to help you get started.
For example, we have defined a “concatenate” function for you (see below) which concatenates
a given list of strings into a single string and returns it. Read the docstring, which explains
what the function is supposed to do. Then write your code where it says “# TODO” to
implement the function. You’ll do this for each function in the program.
def concatenate(strings):
"""
Concatenates the given list of strings into a single string.
Returns the single string.
If the given list is empty, returns an empty string.
For example:
- If we call concatenate(["a","b","c"]), we'll get "abc" in
return
- If we call concatenate([]), we'll get "" in return
"""
# TODO
We’ll run a Python test script against your program to test whether each function
implementation is correct and whether you have considered enough cases. Examples of cases
have been provided in the docstrings.
Introduction to Python Programming
The main function has been completely implemented for you (see example snippet below). Use
it to run and interact with your program, and to see if your functions are working as expected.
Spend some time on testing.
def main():
"""
Calls all the functions above to see whether they've been
implemented correctly.
"""
# test concatenate
print("test concatenate")
word = concatenate(["b", "e", "a", "t", "l", "e", "s"])
print(word == "beatles")
print("=" * 50)
Submission
Open the Jupyter Notebook directly in Coursera (you will find it in the item following this
reading). To complete the assignment, complete the provided Jupyter Notebook file, following
the detailed instructions in each cell. Test your submission before submitting by following the
instructions on the assignment page in Coursera. When you’re happy with your solutions, click
the ‘Submit Assignment’ button in the top right.
Evaluation