Example #1
0
def main():
    """
    The main program.
    :return None
    :rtype: NoneType
    """

    # prompt for the satchels weight capacity, e.g. 55
    satchelCapacity = int(input("Enter satchel's maximum weight (int): "))
    mySatchel = satchel.createSatchel("Greedo's Satchel", satchelCapacity)

    # prompt for the filename, e.g. precious.txt
    fileName = input('Enter metals file name (in data/): ')

    # read and display the unsorted metals from the file
    print('\nThe metals read from', fileName, ':')
    myMetals = metal.readMetals(fileName)
    metal.printMetals(myMetals)

    # sort the metals by value per bar (ignoring weight)
    print('\nThe metals sorted by value per weight:')
    metal.sortMetalsByValuePerWeight(myMetals)
    metal.printMetals(myMetals)

    # fill the satchel greedily by weight value and display result
    print('\nFilling the satchel greedily by weight value:')
    satchel.fillSatchel(mySatchel, myMetals)
    satchel.printSatchel(mySatchel)
Example #2
0
def main():
    """
    The main program.
    :return None
    :rtype: NoneType
    """

    # prompt for the satchels weight capacity, e.g. 55
    satchelCapacity = int(input("Enter satchel's maximum weight (int): "))
    mySatchel = satchel.createSatchel("Greedo's Satchel", satchelCapacity)

    # prompt for the filename, e.g. precious.txt
    fileName = input('Enter metals file name (in data/): ')

    # read and display the unsorted metals from the file
    print('\nThe metals read from', fileName, ':')
    myMetals = metal.readMetals(fileName)
    metal.printMetals(myMetals)

    # sort the metals by value per bar (ignoring weight)
    print('\nThe metals sorted by value per weight:')
    metal.sortMetalsByValuePerWeight(myMetals)
    metal.printMetals(myMetals)

    # fill the satchel greedily by weight value and display result
    print('\nFilling the satchel greedily by weight value:')
    satchel.fillSatchel(mySatchel, myMetals)
    satchel.printSatchel(mySatchel)
Example #3
0
def printSatchel(satchel):
    """
    Display the satchel to standard output in the format:
        Name: {name of satchel}
        Capacity: {maximum weight of satchel}
        Weight Held: {current weight of satchel}
        Total Value: {total value of satchel}
        Items:
            {first metal}
            {second metal}
            ...
    When displaying the individual metals, use the metal module function,
    printMetals().
    :param satchel (Satchel): The Satchel object
    :return: None
    :rtype: NoneType
    """

    print("Name: ", satchel.name)
    print("Capacity: ", satchel.capacity)
    print("Weight Held: ", satchel.weight)
    print("Total Value: ", satchel.totalValue)
    print("Items:")
    printMetals(satchel.items)
Example #4
0
def printSatchel(satchel):
    """
    Display the satchel to standard output in the format:
        Name: {name of satchel}
        Capacity: {maximum weight of satchel}
        Weight Held: {current weight of satchel}
        Total Value: {total value of satchel}
        Items:
            {first metal}
            {second metal}
            ...
    When displaying the individual metals, use the metal module function,
    printMetals().
    :param satchel (Satchel): The Satchel object
    :return: None
    :rtype: NoneType
    """

    print("Name: ", satchel.name)
    print("Capacity: ", satchel.capacity)
    print("Weight Held: ", satchel.weight)
    print("Total Value: ", satchel.totalValue)
    print("Items:")
    printMetals(satchel.items)