Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program called MakeChange to produce change from one dollar for any purc

ID: 3750281 • Letter: W

Question

write a program called MakeChange to produce change from one dollar for any purchase less than one dollar.

The program should display the name (e.g. dime, nickel, etc.) and amount of each coin. It should minimize the number of coins (68 pennies would not be appropriate way to make change for 68 cents). The parameter is the amount of purchase.

For example, change for a purchase of 58 cents would be 1 quarter, 1 dime, 1 nickel, and 2 pennies.

Step 1 - draw a flowchart to represent your algorithm (answers.pdf).

Step 2 - use a trace table to test your algorithm for a purchase of 58 cents (answers.pdf).

Step 3 - write a python program corresponding to your algorithm (MakeChange.py)

Explanation / Answer

print "Change Calclator"

quarterr = 25
dimee = 10
nickell = 5
pennyy = 1

money_given = raw_input("Enter how much money given: ")
c_item = raw_input("How much did the item cost?: ")
money_given = int(float(money_given) * 100)
c_item = int(float(c_item) * 100)
moneyback = money_given - c_item

qmb = moneyback / quarterr
partialtotal = moneyback - qmb * quarterr
dmb = partialtotal
dpartialtotal = partialtotal - dmb * dimee
nmb = dpartialtotal
npartialtotal = dpartialtotal - nmb * nickell
pmb = npartialtotal
ppartialtotal = npartialtotal - pmb * pennyy
print "You need %s quarters, %s dimes, %s nickels, %s pennies." % (qmb, dmb, nmb, pmb)