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???
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
Join our real-time social learning platform and learn together with your friends!