

def knapsackLight(value1, weight1, value2, weight2, maxW):
    if weight1 + weight2 <= maxW:
        return value1 + value2
    else:
        return max([v for v, w in zip((value1, value2), (weight1, weight2))
                   if w <= maxW] + [0])


def main():
    tests = [
        []
    ]

    for t in tests:
        res = knapsackLight(t[0], t[1], t[2])
        ans = t[3]
        if ans == res:
            print("PASSED: knapsackLight({}, {}, {}) returned {}"
                  .format(t[0], t[1], t[2], res))
        else:
            print(("FAILED: knapsackLight({}, {}, {}) returned {},"
                   "answer: {}").format(t[0], t[1], t[2], res, ans))


if __name__ == '__main__':
    main()



def knapsackLight(value1, weight1, value2, weight2, maxW):
    if weight1 + weight2 <= maxW:
        return value1 + value2
    else:
        return max([v for v, w in zip((value1, value2), (weight1, weight2))
                   if w <= maxW] + [0])


def main():
    tests = [
        [10, 5, 6, 4, 8, 10],
        []
    ]

    for t in tests:
        res = knapsackLight(t[0], t[1], t[2], t[3], t[4])
        ans = t[5]
        if ans == res:
            print("PASSED: knapsackLight({}, {}, {}, {}, {}) returned {}"
                  .format(t[0], t[1], t[2], t[3], t[4], res))
        else:
            print(("FAILED: knapsackLight({}, {}, {}, {}, {}) returned {},"
                   "answer: {}")
                  .format(t[0], t[1], t[2], t[3], t[4], res, ans))


if __name__ == '__main__':
    main()

Format Code Fights knapsack light problem
Format Code Fights knapsack light problem

  
  
  def knapsackLight(value1, weight1, value2, weight2, maxW):
      if weight1 + weight2 <= maxW:
          return value1 + value2
      else:
          return max([v for v, w in zip((value1, value2), (weight1, weight2))
                     if w <= maxW] + [0])
  
  
  def main():
      tests = [
+         [10, 5, 6, 4, 8, 10],
          []
      ]
  
      for t in tests:
-         res = knapsackLight(t[0], t[1], t[2])
+         res = knapsackLight(t[0], t[1], t[2], t[3], t[4])
-         ans = t[3]
+         ans = t[5]
          if ans == res:
-             print("PASSED: knapsackLight({}, {}, {}) returned {}"
+             print("PASSED: knapsackLight({}, {}, {}, {}, {}) returned {}"
-                   .format(t[0], t[1], t[2], res))
+                   .format(t[0], t[1], t[2], t[3], t[4], res))
          else:
-             print(("FAILED: knapsackLight({}, {}, {}) returned {},"
+             print(("FAILED: knapsackLight({}, {}, {}, {}, {}) returned {},"
+                    "answer: {}")
-                    "answer: {}").format(t[0], t[1], t[2], res, ans))
+                   .format(t[0], t[1], t[2], t[3], t[4], res, ans))
  
  
  if __name__ == '__main__':
      main()
  
Format Code Fights knapsack light problem
## Code Before:


def knapsackLight(value1, weight1, value2, weight2, maxW):
    if weight1 + weight2 <= maxW:
        return value1 + value2
    else:
        return max([v for v, w in zip((value1, value2), (weight1, weight2))
                   if w <= maxW] + [0])


def main():
    tests = [
        []
    ]

    for t in tests:
        res = knapsackLight(t[0], t[1], t[2])
        ans = t[3]
        if ans == res:
            print("PASSED: knapsackLight({}, {}, {}) returned {}"
                  .format(t[0], t[1], t[2], res))
        else:
            print(("FAILED: knapsackLight({}, {}, {}) returned {},"
                   "answer: {}").format(t[0], t[1], t[2], res, ans))


if __name__ == '__main__':
    main()

## Instruction:
Format Code Fights knapsack light problem
## Code After:


def knapsackLight(value1, weight1, value2, weight2, maxW):
    if weight1 + weight2 <= maxW:
        return value1 + value2
    else:
        return max([v for v, w in zip((value1, value2), (weight1, weight2))
                   if w <= maxW] + [0])


def main():
    tests = [
        [10, 5, 6, 4, 8, 10],
        []
    ]

    for t in tests:
        res = knapsackLight(t[0], t[1], t[2], t[3], t[4])
        ans = t[5]
        if ans == res:
            print("PASSED: knapsackLight({}, {}, {}, {}, {}) returned {}"
                  .format(t[0], t[1], t[2], t[3], t[4], res))
        else:
            print(("FAILED: knapsackLight({}, {}, {}, {}, {}) returned {},"
                   "answer: {}")
                  .format(t[0], t[1], t[2], t[3], t[4], res, ans))


if __name__ == '__main__':
    main()
