Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (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

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!