At Westonci.ca, we make it easy to get the answers you need from a community of informed and experienced contributors. Our Q&A platform offers a seamless experience for finding reliable answers from experts in various disciplines. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

Dog feeder - Depending on their weight and age, we need to know how many pounds of food to feed our dog each day! /* Use the hungryDog function and feeding requirements below to do the following:
1. Invoke the hungryDog function below and pass it a weight value in pounds
2. Also, pass to hungryDog an age value in years (note: if the dog is a puppy, the age will be a decimal. For example: three months = 3/12 or .25)
3. Do the proper calculations and return the number of pounds of raw food to feed the dog/puppy in a day


Sagot :

See comment for program requirements:

Answer:

The function in Python is as follows:

def hungryDog(weight,age):

   if age >= 1:

       if weight <= 5:

           feed = 0.05 * weight

       elif weight >= 6 and weight <= 10:

           feed = 0.04 * weight

       elif weight >= 11 and weight <= 15:

           feed = 0.03 * weight

       else:

           feed = 0.02 * weight

   else:

       if weight >= 0.167 and weight <= 0.333:

           feed = 0.10 * weight

       elif weight > 0.333 and weight <= 0.583:

           feed = 0.05 * weight

       elif weight > 0.583:

           feed = 0.04 * weight

   return feed

Explanation:

This defines the function

def hungryDog(weight,age):

If age is 1 and above

   if age >= 1:

If weight is less than 5

       if weight <= 5:

Feed is 5% of weight

           feed = 0.05 * weight

if weight is between 6 and 10

       elif weight >= 6 and weight <= 10:

Feed is 4% of weight

           feed = 0.04 * weight

if weight is between 11 and 15

       elif weight >= 11 and weight <= 15:

Feed is 3% of weight

           feed = 0.03 * weight

If weight is above 15

       else:

Feed is 2% of weight

           feed = 0.02 * weight

If age is less than 1

   else:

If weight is between 2 and 4 months

       if weight >= 0.167 and weight <= 0.333:

Feed is 10% of weight

           feed = 0.10 * weight

If weight is between 4 and 7 months

       elif weight > 0.333 and weight <= 0.583:

Feed is 5% of weight

           feed = 0.05 * weight

If weight is above 7 months

       elif weight > 0.583:

Feed is 4% of weight

           feed = 0.04 * weight

This returns the feed

   return feed