I thought I had cracked pset 1 (greedy) but when I submitted the code it was finding errors with some of my calculations. The main one that i struggle with is where it states that it is expecting an answer of 4 for 0.41, whereas my result (which I thought was right) is giving the answer 1 x quarter, 1 x nickel x dime, 1 x penny (i.e. giving the smallest number of coins, and going down from the biggest to the smallest)

Is anyone able to give me a hint as to what I've done incorrectly here? Thank you so much.enter image description hereenter image description here


One of the hidden lessons in the first few psets is to write the code EXACTLY to the specification, not close, and not what you think is better. This is extremely important in team programming when lots of programmers are writing different parts that have to fit together perfectly later.

So, with that in mind, the spec says to output the NUMBER of coins, not a listing of how many of each type. See the difference? ;-) You managed to calculate what was needed, but the output is still incorrect. It should just be a number, in this case, 4.

Also, remember that these psets are machine graded. It doesn't care how brilliant we think we are, it just wants exactly and precisely what it wants. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .