Ok guys so i am trying to create 2 versions of a program which sorts items into boxes. The first version i have to create puts the item weights (integer between 1 and 20) into the first "box" they will fit into. So given the input 11,17,3,5,4 the list the program would out put would be 19,17,4. This version i have working fine.
The next version has to put the integers into the boxes in which they will fit best. The code is exactly the same as my first version except i have changed the function which calculates which list item to add the weight to. Basically i have changed the function however is still gives the same output as the first version, i know its somewhere in the function im going wrong, just hoping a fresh pair of eyes could give it the once over and help me out, thanks a million.
def findcontainer(conweights, itemweight):
count = 0
gcount = 0
greatest = itemweight
while count < len(conweights):
if conweights[count] + itemweight >= greatest and conweights[count] + itemweight <= 20:
greatest = conweights[count] + itemweight
gcount = count
return gcount
count = count + 1
return -1
containerweights = []
itemweightlist = []
serial = []
itemweight = input("Please enter the first item weight. Enter zero to end.")
while itemweight != 0:
if findcontainer(containerweights, itemweight) != -1:
containerweights[findcontainer(containerweights, itemweight)] = containerweights[findcontainer(containerweights, itemweight)] + itemweight
elif findcontainer(containerweights, itemweight) == -1:
containerweights = containerweights + [0]
containerweights[findcontainer(containerweights, itemweight)] = containerweights[findcontainer(containerweights, itemweight)] + itemweight
itemweightlist = itemweightlist + [itemweight]
itemweight = input("Please enter the next item weight. Enter zero to end.")
count = 0
while count < len(itemweightlist):
print "Item", (count + 1),",", "Weight", itemweightlist[count],":", "Container"
count = count + 1
print "Container Weights:", containerweights
thanks again