Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

(Mit Problem Set 2) problem 3 http://dpaste.com/hold/667748/ this is my code .... where am i going wrong?

OpenStudy (anonymous):

this is the question "Problem 3. Write an iterative program that finds the largest number of McNuggets that cannot be bought in exact quantity. Your program should print the answer in the following format (where the correct number is provided in place of <n>): “Largest number of McNuggets that cannot be bought in exact quantity: <n>”"

OpenStudy (anonymous):

print "Enter the first package value " a=raw_input() print "Enter the second package value " b=raw_input() print "Enter the third package value " c=raw_input() s=1 x=0 f=int(a) ser=[i for i in range(51)] print ser while True: if(s>=int(a)): for i in range(0,s+1): m=i*int(a) for j in range(0,s+1): n=j*int(b) for k in range(0,s+1): o=k*int(c) e=m+n+o if(e==int(s)): print e g=int(f) f=int(e) if(e<=50): if((f-g)>=1): ser.remove(e) print ser if(e>=50): ser.reverse() print "Largest till 50 " ,ser[0] exit() if((f-g)==1): x=x+1 if((f-g)>1): x=0 if(x==5 and e<40): print "Largest number of McNuggets that cannot be bought in exact quantity: ",(e-6) exit() s=s+1 Check This Code ....Hope it Helps...use python 2.x interpreter... :)

OpenStudy (anonymous):

Sorry to paste it here... you can connect here too.... http://dpaste.com/hold/667831/

OpenStudy (anonymous):

What did you have in mind for your variable tester to do?

OpenStudy (anonymous):

looks like your for loops are working and line 15 will tell you if the nuggets can be bought - now you have to do something with it. can you explain what lines 16- 19 do?

OpenStudy (anonymous):

These three loops...are checking all the possible combination of Nuggets..and adding them at variable "e"...which again check that value for the desired total number of nuggets...please follow the code with different simulation if you want to understand it properly... :)...hope it helps...

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!