anonymous
  • anonymous
cannot figure out how to end my loop. i see that the last line is within the main FOR loop, so that's why it's printing. do i need to add a while loop? i'm stuck. n=raw_input ("Enter # to test: ") n=int(n) for c in range (0,n): remainder = n-(20*c) for b in range (0,n): a = remainder-(9*b) a = a/6 if 6*a + 9*b + 20*c == n: if a>=0 and b>=0 and c>=0: print n," can be bought",a,b,c print n," cannot be bought" if i enter 6, i get: Enter # to test: 6 6 can be bought 1 0 0 6 cannot be bought # don't want this last line to print
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Your print statement is treated as coming after all the other elements in the program. You could try adding an else statement after your final if and then printing The else statement needs the same indentation as your final if statement then indent the print under the else. This should have your print statement running when no solution is found.
anonymous
  • anonymous
You can use the "break" function to end any for or while loop.
anonymous
  • anonymous
You need an else which goes with the if 6*a + 9*b + 20c==n: else print n, "cannot be bought" Not familiar with this language but that is what you need.

Looking for something else?

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

More answers

anonymous
  • anonymous
when i add the else clause to the if 6*a..., it prints n,"cannot be bought" each time it completes a loop. so when i try n=6, i get: 6 can be bought 1 0 0 6 cannot be bought 6 cannot be bought ... i can't figure out a way for it to stop once it finds that n CAN be bought

Looking for something else?

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