title: Recursion not entering base case
body: <p>when i run this program i am getting index out of range error. what i did wrong why it's not working</p>
  
  <pre><code>def knapsack(p, w, capacity, idx):
      if capacity &lt;= 0 or 0 &gt; idx &gt;= len(p):
          return 0
      profit_1 = 0
      if w[idx] &lt;= capacity:
          profit_1 = p[idx] + knapsack(p, w, capacity - w[idx], idx + 1)
      profit_2 = knapsack(p, w, capacity, idx + 1)
      return max(profit_1, profit_2)
  
  
  p = [31, 26, 72, 17]
  w = [3, 1 , 5, 2]
  
  print(knapsack(p, w, 7, 0))
  </code></pre>
  
  <p>It's not entering base case </p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/komat/PycharmProjects/DSA/divide&amp;conquer/knapsack.py", line 14, in &lt;module&gt;
      print(knapsack(p, w, 7, 0))
    File "C:/Users/komat/PycharmProjects/DSA/divide&amp;conquer/knapsack.py", line 6, in knapsack
      profit_1 = p[idx] + knapsack(p, w, capacity - w[idx], idx + 1)
    File "C:/Users/komat/PycharmProjects/DSA/divide&amp;conquer/knapsack.py", line 6, in knapsack
      profit_1 = p[idx] + knapsack(p, w, capacity - w[idx], idx + 1)
    File "C:/Users/komat/PycharmProjects/DSA/divide&amp;conquer/knapsack.py", line 7, in knapsack
      profit_2 = knapsack(p, w, capacity, idx + 1)
    File "C:/Users/komat/PycharmProjects/DSA/divide&amp;conquer/knapsack.py", line 6, in knapsack
      profit_1 = p[idx] + knapsack(p, w, capacity - w[idx], idx + 1)
    File "C:/Users/komat/PycharmProjects/DSA/divide&amp;conquer/knapsack.py", line 5, in knapsack
      if w[idx] &lt;= capacity:
  IndexError: list index out of range
  </code></pre>