A community for students.

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

  • 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

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.