Hello all I am new to Python and I am taking a programming class but I can't seem to figure out what I am doing wrong to get the programming correct. I have the following but it isn't working correctly.

print ("Change Calclator")

quarter = .25
dime = .10
nickel = .05
penny = .01

moneygiven = int(input("Enter how much money given: "))
citem = int(input("How much did the item cost?: "))
moneygiven = int(float(moneygiven) 100)
citem = int(float(citem)
moneyback = int(float(moneygiven - citem))

qmb = moneyback / quarter
partialtotal = int(float(moneyback - qmb quarter))
dmb = partialtotal / dime
dpartialtotal = int(float(partialtotal - dmb
nmb = dpartialtotal / nickel
npartialtotal = int(float(dpartialtotal - nmb nickel))
pmb = npartialtotal / penny
ppartialtotal = int(float(npartialtotal - pmb

print ("You need %s quarters, %s dimes, %s nickels, %s pennies.")

This is what happens when I run the program

Change Calclator
Enter how much money given: 99
How much did the item cost?: 55
You need %s quarters, %s dimes, %s nickels, %s pennies.

However it is supposed to tell me this information

  1. The program should display the minimum number of quarters, dimes, nickels, and pennies that one needs to make up the specified number of cents.
  2. Assume that the user will enter a valid integer for the number of cents.
  3. The program should continue only if the user enters "y" or "Y" to continue.

I think that I may not have enough information listed in my source code or I may not have the correct information but either way I am lost. If anyone can point me in the right direction it is definitely appreciated.

Recommended Answers

All 3 Replies

What are you waiting to happen here?

print ("You need %s quarters, %s dimes, %s nickels, %s pennies.")

You need to understand how formatted print works in Python. You have forgotten to pass the variables at the end of the print method after the "%" especial character.

Try this:

print ("You need %s quarters, %s dimes, %s nickels, %s pennies." % (partialtotal, dpartialtotal, npartialtotal, ppartialtotal ))

If you are using python 3.x you should use this way of doing format print:

print("You need {} quarters, {} dimes, {} nickels, {} pennies.".format(partialtotal, dpartialtotal, npartialtotal, ppartialtotal ))


  1. Store all values as cents (integers) to avoid conversion/rounding problems.
  2. Create a list of change denominations from largest to smallest
  3. Use a loop with that list
commented: Good idea. Don't need a Superman III repeat. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.