Cover Image for Denomination Program in Python
182 views

Denomination Program in Python

A denomination program in Python is a program that takes an amount and calculates the minimum number of each denomination of currency (bills and coins) needed to make up that amount. For example, if the input is $47.50, the program should calculate how many $20 bills, $10 bills, $5 bills, $1 bills, quarters, dimes, nickels, and pennies are needed to make up the total.

Here’s a simple denomination program in Python:

Python
def calculate_denominations(amount):
    # Define the denominations and their values
    denominations = {
        'twenties': 20,
        'tens': 10,
        'fives': 5,
        'ones': 1,
        'quarters': 0.25,
        'dimes': 0.10,
        'nickels': 0.05,
        'pennies': 0.01
    }

    # Initialize a dictionary to store the count of each denomination
    counts = {denomination: 0 for denomination in denominations}

    # Convert the amount to cents (to avoid floating-point issues)
    cents = int(amount * 100)

    # Calculate the number of each denomination needed
    for denomination, value in denominations.items():
        count = cents // int(value * 100)
        cents -= count * int(value * 100)
        counts[denomination] = count

    return counts

# Input the amount
amount = float(input("Enter the amount: $"))

# Calculate and print the denominations
denominations = calculate_denominations(amount)
for denomination, count in denominations.items():
    if count > 0:
        print(f"{count} {denomination}")

You can run this program and input any amount, and it will calculate the minimum number of each denomination needed to make up that amount. The denominations are defined in the denominations dictionary, and the program iterates through them to calculate the counts.

Example usage:

Plaintext
Enter the amount: $47.50
2 twenties
0 tens
0 fives
2 ones
2 quarters
0 dimes
0 nickels
0 pennies

Feel free to modify and expand this program to suit your needs or to handle different currencies and denominations.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS