Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 4 years ago

I watching this lecture video and I get a wrong result,( skip video to 29:53). link: ---------------------------------------------------------------------- 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

  • This Question is Closed

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy