Will anybody review my problem set 2 for correctness? capture = () x = input("Package size 1: ") y = input("Package size 2: ") z = input("Package size 3: ") for n in range(1,201): can_buy = 0 for a in range(0,(n/x)+1): for b in range(0,(n/y)+1): for c in range(0,(n/z)+1): if x*a + y*b + z*c == n: can_buy = 1 print n, " can by bought: ",a,b,c if can_buy == 0: print n, " cannot be bought" capture += (n,) print "Largest number of McNuggets that cannot be bought in exact quantity: ",capture
Hey your code works but on the very last line you don't want it to print all the captures only the last so change capture to capture[-1] the negative one represents the last place in the tuple. Also your range is really high so either you can take out the print statements and it will run faster or make your range like (1,50) I already know the answer that's why I say 50 but yes normally you would need a higher range.
If you have another question on what I did or whatever feel free to ask.
Hey Onyx, thanks a lot. I'm now your fan. As for the last line, I think the [-1] got cut off by the chat box without me realizing it!
Join our real-time social learning platform and learn together with your friends!