Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 10 Online
OpenStudy (anonymous):

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???

OpenStudy (anonymous):

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

OpenStudy (rsmith6559):

You're probably making an indentation error. What you posted should behave just as you describe it behaving.

OpenStudy (hunus):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!