Python Programs to Find the Minimum Number of Currency Notes to Make an Amount N

Currency notes

Python programs to find the minimum number of currency notes which sum up to the given amount N, are given here. The quantity of each type of note for the amount is also shown.



Page content(s):

1. Program & output

1.1. Python




1. Program to Find the Minimum Number of Currency Notes to Make an Amount N




1.1. Python Program to Find the Minimum Number of Currency Notes to Make an Amount N

Code has been copied
# **************************************************
# 	        alphabetacoder.com
# Python program to find the minimum number of
# currency notes which sum upto the given amount N
# **************************************************

# declare a list to store different currency value
currency = [500, 200, 100, 50, 20, 10, 5, 2, 1]

# take input
N = int(input("Enter an amount: "))

# initialize
t = 0
# new line
print("")

# count the total no of currency unit
for i in range(0, len(currency)):
    k = N // currency[i]
    # display result for current unit
    print(currency[i], "required: ", k)
    # add to counter
    t = t + k
    # calculate remaining amount
    N = N - k * currency[i]

# display total
print("\nMinimum no. of notes required: ", t)

Output


Enter an amount: 2789


500 required: 5

200 required: 1

100 required: 0

50 required: 1

20 required: 1

10 required: 1

5 required: 1

2 required: 2

1 required: 0


Minimum no. of notes required: 12