A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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
anonymous
 5 years ago
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

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Hey 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0If you have another question on what I did or whatever feel free to ask.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Hey 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!
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.