I have been writing this program to add up money in a cash box. when I started multiplying I realized I needed to make a change in my code. int(1) * float(0.05)
gave me 0.050000000000000003. I tried searching how to round it and I read that float
will not accurately represent currency, I also found information about decimal
and quatitize ()
. I tried to understand how to incorporate that into my code and I am struggling. how can accurately represent currency in my code?
money = {'nickles' : 0, 'dimes' : 0, 'quarters': 0, 'ones': 0, 'twos': 0, 'tens' : 0, 'twenties' : 0, 'fifties': 0, 'one hundreds' : 0}
def display_values():
print(money['nickles'], 'nickles = ', money['nickles'] * 0.05, 'cents')
def assign_all_values():
input_nickles()
input_dimes()
input_quarters()
input_ones()
input_twos()
input_fives()
input_tens()
input_fifties()
input_one_hundreds()
def input_nickles():
money['nickles'] = float(input('how many nickels are in your cash box? '))
display_values()
def input_dimes():
money['Dimes'] = float(input('how many dimes are in your cash box? '))
display_values()
def input_quarters():
money['Quarters'] = float(input('how many quarters are in your cash box? '))
display_values()
def input_ones():
money['Ones'] = int(input('how many one dollar coins are in your cash box? '))
display_values()
def input_twos():
money['twos'] = int(input('how many one two dollar coins are in your cash box? '))
display_values()
def input_fives():
money['fives'] = int(input('how many five dollar bills are in your cash box? '))
display_values()
def input_tens():
money['Tens'] = int(input('how many ten dollar bills are in your cash box? '))
display_values()
def input_twenties():
money['Twenties'] = int(input('how many twenty dollar bills are in your cash box? '))
display_values()
def input_fifties():
money['fifties'] = int(input('how many fifty dollar bills are in your cash box? '))
display_values()
def input_one_hundreds():
money['one hundreds'] = int(input('how many one hundred dollar bills are in your cash box '))
display_values()
def change_value():
entry = input("what value would you like to change?\n1. One dollar")
assign_all_values()