This demo shows several functions:

  • One takes in input and returns whether or not that input is odd.
  • Another takes in input and a divisor and returns the quotient using the integer division // operator.
  • A third takes in input and a divisor and returns the remainder using the modulo % operator.

Solution

"""
File: division.py
-------------------
This program shows various division functions.
"""
def main():
    show_info(505)
    show_info(995)
    show_info(737)
def show_info(valuedivisor):
    """
    Prints out information about the given value with the given divisor,
    including whether the value is even or odd, what the integer division result
    of value / divisor is, and what the remainder of that operation is.
    """
    print("value = " + str(value))
    print("    is odd? " + str(is_odd(value)))
    print("    value / " + str(divisor)
          + " = " + str(divide(valuedivisor))
          + " remainder " + str(remainder(valuedivisor)))
def is_odd(value):
    """
    Returns True if value is odd, False otherwise.
    """
    return (value % 2) == 1
def divide(valuedivisor):
    """
    Performs integer division for value / divisor.
    """
    return value // divisor
def remainder(valuedivisor):
    """
    Returns remainder of the integer division for value / divisor.
    """
    return value % divisor
if __name__ == '__main__':
    main()
X