Someone has 100 Yuan , buy 100 chicken . cock 5 One yuan , hen 3 One yuan , Chick 1 Three yuan .
ask : You can buy roosters 、 hen 、 How many chickens each .
Use the exhaustive method , Try every possibility , Get the final correct result .
If the cock is x only , Hen is y only , The chicken is z only ;
We will get the formula : 5x+3y+z/3=100; also
x+y+z=100;
Chicken number divided by 3 The remainder of must be 0
money=100
score=0
for x in range(1,21): # A hundred dollars can buy at most 20 A rooster
for y in range(34): # A hundred dollars can buy at most 33 A hen
for z in range(301): # A hundred dollars can buy at most 300 A chicken
score=5 * x + 3 * y + z / 3
if score==money and x+y+z==100 :
print(' The cock is %s only , The hen is %s only , Chicken is %s only '%(x,y,z))
If you have a better solution or have different opinions , You can say what you want , Jointly improve progress !
I'm also Xiaobai , Dare to ask questions , Let's discuss , Learn together and make progress !