<p>This is the <a href="https://en.wikipedia.org/wiki/Change-making_problem" rel="nofollow noreferrer">Change-making problem</a>. It can be solved using the greedy approach which works really well when the problem has the greedy choice.</p>
<p>This algorithm works for &quot;<a href="https://arxiv.org/abs/0809.0400" rel="nofollow noreferrer">canonical coin systems</a>&quot;, systems where each value (coin value in our example) is at least double the value of the item before it.</p>
<p>You can see that if you give as input lets say <strong>Amount:</strong> 40 and <strong>Coins_available:</strong> [20, 10, 5, 2, 1] - Then it works perfectly,</p>
<p>but for  <strong>Amount:</strong> 40 and <strong>Coins_available:</strong> [25, 20, 10, 5, 2, 1] - Check to see what we get.</p>
<pre><code>def min_coin(amount, coins_available):

# Making sure your coin array is sorted in descending order
# This way we make sure to include the largest possible coin each time
coins_available.sort(reverse=True)

# Initializing our array that will hold the coins we choose
selected_coins = []

for i in range(len(coins_available)):
    while (amount &gt;= coins_available[i]):
        
        # Evey time we pick a coin, we reduce the amount left by that coin's amount
        amount -= coins_available[i]
        selected_coins.append(coins_available[i])

    if(amount == 0):
        break;

for coin in selected_coins:
    print(coin)
 
</code></pre>
<p>In this solution I simplified some statements and removed unnecessary variables.</p>
<p>Try to avoid using global variables and also you can do the printing from within the function, otherwise you can just return the list and use it as you wish.</p>
<p>The way it works is it looks for the largest (in terms of value) coin we have, then checks if we can give it as change, if yes, we give it as change, reduce the amount left and check again. Once the amount left is less that the largest coin we move to the second largest.</p>
<p>This way we know our program is correct because the underlying algorithm is correct. Try to answer yourself why.</p>
<p>Hint:</p>
<blockquote class="spoiler">
<p> See if you can assume that the solution is wrong and come up with a &quot;correct&quot; one, if you cant then its correct)</p>
</blockquote>
<p>I hope this helped in understanding.</p>
Minimum coins needed to sum up an amount
<p>This is the <em>minimum coins</em>, problem.</p>
<p>I am not able to handle the case when the return type of function is <code>None</code>. I tried something like <code>if  min_count != None &amp;&amp; min_count &lt;= counter:</code> but this is not so proper.</p>
<p>Please tell me the correct way of doing this.</p>
<pre class="lang-py prettyprint-override"><code># min coin problem using a recursive approach
# this program is giving me all the solutions available in all combination

counter = 10000
def min_coin(Amount,coins_available,count):
    global counter
    if (Amount == 0):
        return count
    for i in coins_available:
        if Amount &gt;= i:
            min_count =  min_coin(Amount - i,coins_available,count+1)
        if  min_count &lt;= counter:
            counter = min_count

Amount = 2
coins_available = [1,2]

count = 0
min_coin(Amount,coins_available,count)
print(counter)

</code></pre>