Question: CODING IN PYTHON Suppose there is a retail store where clients buy goods. Each cashier in the store will be provided with a program which
CODING IN PYTHON
Suppose there is a retail store where clients buy goods. Each cashier in the store will be provided with a program which given the cost of the item the client is buying and the amount of bills and coins the user is paying with, will provide the least amount of bills and coins needed to give change to the client. Assume that there are six kinds of bills, with values $100, $50, $20, $10, $5, and $1. And only four types of coins, with the following names and values: penny 1 cent, nickel 5 cents, dime 10 cents, and quarter 25 cents.
Some examples follow:
The cost of the item is $15.65 and the client pays with a $20 bill. The change to be provided is 4 $1 bills, one quarter and one dime.
The cost of the item is $19.99 and the client pays with a $50 bill. The change to be provided is 1 $20 bill, one $10 bill, and one penny.
I understand how to get the change but I have absolutely no idea how to get an output broken down into different bill categories like the examples above,
here is my attempt, though I'm certain it is mostly wrong:
cost = float(input('Cost: ')) cost = int(float(cost) * 100) amount_paid = float(input('Amount paid: ')) amount_paid = int(float(amount_paid) * 100) penny = 1 nickel = 5 dime = 10 quarter = 25 dollar_1 = 100 dollar_5 = 500 dollar_10 = 1000 dollar_20 = 2000 dollar_50 = 5000 dollar_100 = 10000 change = cost - amount_paid hmb = change / dollar_100 partialtotal = change - hmb * dollar_100 fmb = partialtotal // dollar_50 f_partialtotal = partialtotal - fmb * dollar_50 wmb = f_partialtotal // dollar_20 w_partialtotal = f_partialtotal - wmb * dollar_20 tmb = w_partialtotal // dollar_10 t_partialtotal = w_partialtotal - tmb * dollar_10 vmb = t_partialtotal // dollar_5 v_partialtotal = t_partialtotal - vmb * dollar_5 omb = v_partialtotal // dollar_1 o_partialtotal = v_partialtotal - omb * dollar_1 qmb = o_partialtotal // quarter q_partialtotal = o_partialtotal - qmb * quarter dmb = q_partialtotal // dime d_partialtotal = q_partialtotal - dmb * dime nmb = d_partialtotal // nickel n_partialtotal = d_partialtotal - nmb * nickel pmb = n_partialtotal // penny p_partialtotal = n_partialtotal - pmb * penny print('Your change is ' ,hmb, ' hundred dollar bills,') print(fmb, ' fifty dollar bills,') print(wmb, ' twenty dollar bills,') print(tmb, ' ten dollar bills,') print(vmb, ' five dollar bills,') print(omb, ' one dollar bills,') print(qmb, ' quarters,') print(dmb, ' dimes,') print(nmb, 'nickels,') print('and ' ,pmb, ' pennies.') any help would be appreciated, I've tried working out solutions from similar problems but just cant seem to get a correct output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
