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

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Your 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
 5 years ago
Best ResponseYou've already chosen the best response.0You can use the "break" function to end any for or while loop.

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

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