def FindMaxDifference(self): """function that finds the maximum difference between two numerical \ components of a list :returns: the maximum difference found between two components of a \ numerical list :param: list components can be a float or integer """ try: from maxDifference import maxFindDiff logging.info("Assignment06: maxFindDiff was imported successfully") except: print("ImportError:") print("FindMinMax function could not be found") try: self.MaxDiff = maxFindDiff(self.list_) logging.info("Assignment06: MaxDiff attribute assigned to list_") except TypeError: logging.warning("Invalid input: list contains data that mixes \ types or that is not numerical") print("TypeError:") print("Your input is not a list or integer. Make ammends \ accordingly.") except ValueError: logging.warning("Invalid input: list contains data that is not of \ the correct numerical type") print("ValueError") print("Your input is not a valid number. Try again.") logging.debug("Assignment06: MinMax = " + str(maxFindDiff(self.list_)))
def test_MaxDiffr(): from maxDifference import maxFindDiff listV = [1, 2, 3, 6, 10] maxxNum = maxFindDiff(listV) assert maxxNum == 4 findPos = maxFindDiff(listV) assert findPos > 0 listV2 = [1.1, 2.2, 3.6, 8.9] maxxNumFloat = maxFindDiff(listV2) assert maxxNumFloat == 5.3
def main(list1, list2, list3): """Program that when given a list will return the sum of the list, \ a tuple of the min and max from the list, and the maximum difference \ between two adjacent numbers in the list. :param list: Input that is a list of numbers. Can be integers or \ floats :returns: combined sum of a list of numbers :returns: a tuple of the min and max from the list :returns: the maximum difference between two adjacent numbers in the list :raises ImportError: an error is raised if numpy cannot be found :raises TypeError: an error is raised if the data input contains \ combined data types or a string instead of integers or a list :raises ValueError: an error is raised if the data input contains \ unsupported numerical values (i.e. an imaginary number or string) """ import logging import math db_str1 = logging.DEBUG logging.basicConfig(filename="assignment05log.txt", format='%(levelname)s \ %(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=db_str1) logging.info("Beginning of assignment05") print("Max Difference is: " + str(maxFindDiff(list1))) logging.info("Assignment05: Maximum difference found") print("Summation Total is: " + str(summation(list2))) logging.info("Assignment05: Sum of list numbers completed") print("FindMinMax: " + str(FindMinMax(list3))) logging.info("Assignment05: The maximum and minimum were found") logging.info("Assignment 05 program completed successfully")
def maxFindDiff(list1): from maxDifference import maxFindDiff out1 = maxFindDiff(list1) return out1
def main(list1, list2, list3): print("Max Difference is: " + maxFindDiff(list1)) print("Summation Total is: " + summation(list2)) print("FindMinMax: " + FindMinMax(list3))