Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

numheads=int(raw_input('Enter heads ')) numlegs=int(raw_input('Enter Legs ')) for numchik in range(0,numheads+1): numpig=numheads-numchik legstot=numchik*2+numpig*4 if(legstot==numlegs): print numchik,numpig print 'No Answer' in this code when i run the last print statement will execute even if the for loop finds a answer. But if i put the same code inside a function and replace print with return last return will execute only if there is no solution.Why is that???

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

cannot understand what you are trying to describe. it is much easier for all of us if you post the code - please use a code pasting site http://dpaste.com http://pastebin.com http://...manyothers
You're probably making an indentation error. What you posted should behave just as you describe it behaving.
Well you just have print "No Answer" at the bottom of your code, you have to have some conditional like if there is an answer print the answer, else print no answer

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question