MIT 6.00 Intro Computer Science (OCW) 24 Online
OpenStudy (anonymous):

Does anyone have a completed example of PS2, question 3 I could look at?

OpenStudy (anonymous):

what are you having a problem with?

OpenStudy (anonymous):

Here is my code: def solve3(numNuggets): for numTwenties in range(0, numNuggets/20 + 1): for numNines in range(0, (numNuggets - numTwenties*20)/9 + 1): numSixes = (numNuggets - numTwenties*20 - numNines*9)/6 totNuggets = 20*numTwenties + 9*numNines + 6*numSixes while totNuggets == numNuggets: numNuggets = solve3(numNuggets - 1) return numNuggets When I make numNuggets between 44-50 , I get 43, which I believe is the right answer. But when I put in a value like 70, I get a crazy answer like 17, and I can't figure out why...

OpenStudy (anonymous):

Any ideas?

OpenStudy (anonymous):

use dpaste.com or something similar to post your code have you written down on paper what you are trying to do? having a recursive call within a while statement seems like a funny thing to do print statements help when trying to debug your code - they let you see what is actually happening and you can see if it is what you meant to happen. i added one to yours, hope it helps: http://dpaste.com/604576/

OpenStudy (anonymous):

Here is what I have: http://dpaste.com/605624/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!