A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
Why doesn't this code work? PSet 2 #3
ctr = 1
n = 1
while ctr < 6:
for a in range(0, n):
for b in range(0, n):
for c in range(0, n):
if (6 * a) + (9 * b) + (20 * c) == n:
print ctr, 'a, b, c =',a,b,c
ctr += 1
n += 1
else:
n += 1
if x == 6:
print n,'is the highest number of McNuggests'
anonymous
 5 years ago
Why doesn't this code work? PSet 2 #3 ctr = 1 n = 1 while ctr < 6: for a in range(0, n): for b in range(0, n): for c in range(0, n): if (6 * a) + (9 * b) + (20 * c) == n: print ctr, 'a, b, c =',a,b,c ctr += 1 n += 1 else: n += 1 if x == 6: print n,'is the highest number of McNuggests'

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Why does this version work but not my originally listed: ctr = 1 n = 1 nugget_purchase = False while ctr < 6: for a in range(0, n): for b in range(0, n): for c in range(0, n): if (6 * a) + (9 * b) + (20 * c) == n: print a,b,c,'lead to nugget purchase',n nugget_purchase = True if nugget_purchase == True: ctr += 1 nugget_purchase = False elif nugget_purchase == False: print n,'cannot be bought' ctr = 1 n += 1 print n

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Your first code it incremented your ctr and your n under your for loop which means that for every number in the for loop it would add 1 to ctr and n if an answer was found.
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.