Hey I'm new to the site but I'm taking a class that will probably have me here often asking stupid questions. One of my homework problems is create a python program using a while loop to answer the 100 fowl problem. The 100 fowl problem is a farmer sold 100 fowl at the market rooster $5 each, hens $3 each, and hatchlings 3 for $1. Exactly how many roosters, hens, and hatchlings did he sell.

Now I have started writing the program but I can't seem to get it to work. This is what I have come up with so far.

1_roosters = 0
2_hens = 0
3_hatchlings = 0
4_while roosters < 20:
5_____while hens < 33:
6_________while hatchlings < 300:
7_____________if (roosters*5 + hens*3 + hatchlings/3 == 100) and (roosters + hens + hatchlings == 100):
8_________________print [roosters, hens, hatchlings]
9_____________hatchlings = hatchlings +1
10________hens = hens + 1
11____roosters = roosters + 1

When I run the program python return no results. Please help me figure out why im getting no results. Thanks!

Recommended Answers

All 3 Replies

You forgot to reset the hatchlings and hens between loops

def solve():
    roosters = 0
    hens = 0
    hatchlings = 0
    while roosters < 20:
        while hens < 33:
            while hatchlings < 300:
                if (roosters*5 + hens*3 + hatchlings/3 == 100):
                        if (roosters + hens + hatchlings == 100):
                                print [roosters, hens, hatchlings]

                hatchlings +=3
            hens += 1
            hatchlings = 0
        roosters += 1
        hens = 0

I appreciate your help but I then reset them to 0 between loops and python is still not displaying the results.

I take that back I had some indention problems. Thanks for you help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.