Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

kasnwick

  • one year ago

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

  • This Question is Open
  1. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  2. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You're probably making an indentation error. What you posted should behave just as you describe it behaving.

  3. Hunus
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  4. 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...

23

  • 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.