'''
Computer Change Redux

Summary
A program that will take an input dollar amount and classify it into smaller monetary units
'''

def read_dollar_amount_in_pennies():
    
    amount = eval(input("Enter an amount, for example, 11.56: "))
    
    while amount < 0:
        
        amount = eval(input("Error: Enter a positive amount, or zero: "))
        
    pennies = int(amount * 100) 
    
    return amount, pennies
          
          
def calculate_currency_type_amount(pennies, currency_value):
    
    NumberOfCoins = pennies // currency_value
    
    pennies_left = pennies % currency_value
    
    return NumberOfCoins, pennies_left


def main():
    
    amount, pennies = read_dollar_amount_in_pennies()
    
    dollars, pennies_left = calculate_currency_type_amount(pennies, 100)
    
    quarters, pennies_left = calculate_currency_type_amount(pennies_left, 25)
    
    dimes, pennies_left = calculate_currency_type_amount(pennies_left, 10)
    
    nickels, pennies_left = calculate_currency_type_amount(pennies_left, 5)
    
    print("Your amount " + "${:,.2f}".format(amount) + " consists of:\n" 
          + str(dollars) + " dollars\n" 
          + str(quarters) + " quarters\n"   
          + str(dimes) + " dimes\n"
          + str(nickels) + " nickels\n"
          + str(pennies_left) + " pennies")    
    
main()


Scroll to Top