Introduction:
The “denomination_program” is a Python program designed to calculate and display the minimum number of currency notes needed to represent a given amount in rupees. This program utilizes a predefined set of currency denominations to determine the most efficient way to distribute the amount across different note values. It provides an easy and automated solution for counting notes, which can be particularly useful in scenarios such as cash handling, financial calculations, and currency exchange.
Algorithm:
- Initialize the “denominations” list with predefined rupee note values.
- Create an empty dictionary called “notes_count” to store the count of each denomination.
- Accept the user’s input for the amount in rupees.
- Iterate through each denomination in the “denominations” list: a. Check if the remaining amount is greater than or equal to the current denomination. b. If true, calculate the number of notes needed by performing integer division of the remaining amount by the denomination. c. Store the count of notes in the “notes_count” dictionary under the current denomination key. d. Subtract the total value of notes (notes * denomination) from the remaining amount.
- Display the minimum number of notes needed for each denomination based on the “notes_count” dictionary.
The program ensures an optimal distribution of currency notes to represent the given amount, providing an efficient and automated solution for denominating rupee amounts.
Code :
def denomination_program(amount):
denominations = [2000, 500, 200, 100, 50, 20, 10, 5, 1]
notes_count = {}
for denomination in denominations:
if amount >= denomination:
notes = amount // denomination
notes_count[denomination] = notes
amount -= notes * denomination
return notes_count
if __name__ == "__main__":
try:
rupees = int(input("Enter the amount in rupees: "))
notes = denomination_program(rupees)
print("Denominations needed:")
for denomination, count in notes.items():
print(f"{count} notes of {denomination} rupees")
except ValueError:
print("Invalid input. Please enter a valid amount in rupees.")
Input :
Enter the amount in rupees: 1000
Output :
Denominations needed:
2 notes of 500 rupees
Explanation:
The program starts by defining a list of currency denominations called “denominations,” which contains the values of various rupee notes, such as 2000, 500, 200, and so on. It also initializes an empty dictionary called “notes_count” that will store the count of each note denomination needed to represent the given amount.
The core logic of the program involves iterating through the list of denominations. For each denomination, the program checks if the remaining amount is greater than or equal to the current denomination. If this condition is met, it calculates the number of notes of that denomination required by performing integer division (//) of the remaining amount by the denomination value. This count is then stored in the “notes_count” dictionary under the corresponding denomination key. Furthermore, the program subtracts the total value of the notes calculated so far (notes * denomination) from the remaining amount.
This process continues for each denomination in descending order, ensuring that the higher-value notes are used first to minimize the total number of notes required.
Once all the denominations have been considered and the notes count has been determined, the program outputs the result by displaying the number of notes needed for each denomination.