Python Review

For this assignment you will implement and test 4 functions.

Your functions will be implemented in the file my_functions.py and code to test the functions will be written in main.py. I have already implemented one function in my_functions.py and main.py contains code to test this function.

my_functions.py contains function headers and docstrings for the 4 functions that you are to write. Read the docstrings to see what the functions are supposed to do. There is more info on docstrings below.

You may need to search online to figure out how to implement some of the functions. If you are new to Python or want a more complete overview of the basics of Python, see the official Python tutorial: https://docs.python.org/3/tutorial/index.html

Development Environment

I highly recommend completing this assignment within PyCharm. If you clone the assignment repository using the terminal, you can then make a new Pycharm project in the cloned directory. PyCharm will ask you if you want to create a project from existing sources, and here you can say yes.

Alternatively you can clone git repositories directly from within PyCharm. If you are on a Mac, this should just work when you paste in the assignment clone URL. If you are on Windows this might take some more work to set up and it is probably a better idea to clone in the terminal.

PyCharm does not come with a Python interpreter, it needs to use an interpreter that is installed on your computer. If PyCharm has not auto-detected your Python 3 installation, you can manually set the project interpreter by going to the settings (File -> Settings in Windows, PyCharm -> preferences on a Mac) and search for “project interpreter”.

To run a file within PyCharm, you can right click on the file in the list of project files and select “Run ”.

Docstrings

Docstrings are used to write documentation for functions, classes, and modules in Python. Docstrings are similar to comments, but they are stored by the Python interpreter so that the documentation can be accessed using the help() function. Docstrings start and end with triple quotes (""").

A convention has emerged for documenting the parameters and return values for functions. Here is the code for triangle_number(), the function that I provided for you, which illustrates this:

def triangle_number(n):
    """
    Compute the nth triangle number.

    :param n: a non-negative integer
    :return: the nth triangle number
    """

    return (n * (n + 1)) / 2

Submission

Commit your changes to the 2 Python files and push your code to gitkeeper. Tests will be run on your code and you will get an email with results.

If the tests all pass you should see something like this:

============================= test session starts ==============================
platform linux -- Python 3.8.1, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /tmp/tmpi4gb32a1/tests, inifile:
plugins: timeout-1.2.0
collected 5 items

tests.py .....

=========================== 5 passed in 0.02 seconds ===========================

If there are any failures you will see additional information about each failure.

The pep8 utility will also be run on your code to ensure that it conforms to the PEP 8 style guide. For full credit your code must pass all the tests and adhere to PEP 8.