Example Function Structure

All functions should have a triple-quoted comment directly under the def line. This comment should describe:

  1. what the function does

  2. what each parameter is and its type

  3. what the function returns

Here are two examples of well-defined functions:

def letter_count(letter,text):
    """
    Purpose: This function counts the number of occurrences of a given
       letter in a given text.
    Paramters:
      letter (str containing a single character), the letter to search for
      text (str) the text to search in
    Returns: (int) the number of times the letter occurrs in text
    """
    count = 0
    for i in range(len(text)):
        if text[i] == letter:
            count = count + 1
    return count


def print_rules():
    """
    Purpose: Prints the rules of the game to the screen.
    Parameters: None
    Returns: None
    """
    print("Welcome to the game of life!")
    print("Here are the rules: ")
    print("Rule #1: be nice to others")
    print("Rule #2: don't give up")
    print("Rule #3: do your best")