• anonymous
I watching this lecture video and I get a wrong result,( skip video to 29:53). link: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures/lecture-4 ---------------------------------------------------------------------- Does anyone have the source code or can make one the same? I made my own code but it displays the wrong result. can you comment on my source code what I did wrong? ---------------my source code------------------------------------------- >>> def solve(numLegs, numHeads): for numChicks in range(0, numHeads + 1): numPigs = numHeads - numChicks totLegs = 4*numPigs + 2*numChicks if totLegs == numLegs: return [numPigs, numChicks] return [None, None] >>> def barnYard(): heads = int(raw_input('Enter number of Heads: ')) legs = int(raw_input('Enter number of Legs: ')) pigs, chickens = solve(legs, heads) if pigs == None: print 'There is no solution' else: print 'Number of pigs: ', pigs print 'Number Chickens: ', chickens >>> barnYard() Enter number of Heads: 20 Enter number of Legs: 56 There is no solution ------------------It should be------------------------------------------- Enter number of Heads: 20 Enter number of Legs: 56 Number of pigs: 8 Number Chickens: 12
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.

Looking for something else?

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