Python Review

For this assignment you will implement and test 4 functions in Python.

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 will likely 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

One core Python data structure that I did not get to in class is the dictionary. You can read about dictionaries in this section of the tutorial.

I have posted the example code from class in the new Class Code section of this web site.

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 two 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.4.6, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /home/tester/1611349739_hwodgbai/tests, inifile:
collected 5 items

tests.py .....

=========================== 5 passed in 0.03 seconds ===========================

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

The pycodestyle 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.