A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

What do you think about this code for problem 2?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    nugget_pacs=(input("Package Size 1 "),input("Package Size 2 "),input("Package Size 3 ")) # tuople contains nugget package sizes tracker=[] # list which will hold possible combinations not_tracker=[] # list to hold combinations not possible for n in range(1,150): # range of numbers to consider as candidates can_buy=0 for a in range(0,(n/nugget_pacs[0])+1): for b in range(0,(n/nugget_pacs[1])+1): for c in range(0,(n/nugget_pacs[2])+1): if nugget_pacs[0]*a+nugget_pacs[1]*b+nugget_pacs[2]*c ==n: can_buy=1 tracker.append(n) # adds the possible combo to list if tracker.count(n)>1: # if statement to remove repeats tracker.remove(n) if can_buy==0: not_tracker.append(n) # adds value of n not possible to list print 'Possible Combinations are' ,tracker print 'These Combinations are not possible' , not_tracker

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    does it run? I do not get where you are taking nugget_pacs from?

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    woops mom

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    looks alright...if it runs an spits out good results it should be fine

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    # chickennuggets.py # dio equations ### ### template of code for Problem 4 of Problem Set 2, Fall 2008 ### bestSoFar = 0 # variable that keeps track of largest number # of McNuggets that cannot be bought in exact quantity pack = (6,9,20) # variable that contains package sizes lim=55 lima=lim/6 limb=lim/9 limc=lim/20 solution=False list=[] for n in range(1, lim+1): # only search for solutions up to size 150 ## complete code here to find largest size that cannot be bought ## when done, your answer should be bound to bestSoFar solution=False for a in range(lima+1): for b in range(limb+1): for c in range(limc+1): trialn=pack[0]*a+pack[1]*b+pack[2]*c if trialn==n: solution=True break if solution: break if solution: break if solution: savenws=n list.append(n) print n, "has a solution, being", a, b, c if len(list)==6: break else: print n, "does not have a solution" saven=n list=[] print saven, "largest without solution, given package size", pack But I already incorporated that sequence of six from the next assignment...but apart from that it is similar in logic...

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    also I did not save all possible combos...I took the first best and left

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    nugget_pacs is a tuople containing the size of the different packages which is taken in as input from the user. It then callc the specific package size by calling its index

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.