Write a PERL script which calculates the mean of a group of numbers.
In PERL we can also subtract, divide, and multiply. (We can do quite a few other things, but we'll save that stuff for later.) Here's a script which subtracts, divides, and multiplies.
The Arithmetic Mean
Hopefully you already know how to calculate the arithmetic mean, but if you don't we'll go through the steps in just a moment. First, we should discuss the importance of an arithmetic mean. Often we refer to the arithmetic mean as the average of a group of values. For instance, we could weigh all the students in the seventh grade class and from this set of data calculate a mean weight for the class. Alternately, we could be dealing with people suffering from some physical condition which we treat with some new medication. In our study to determine the effectiveness of our new treatment we could collect data on how long it took each person to recover from the physical condition after beginning treatment with our new medication. We could then calculate an average time to recovery for this group of people using our medication. The mean is a handy way of summarizing data.
Remember the weight of living organisms and the time it takes a chemical or biolgical compound to have an effect on an organism are both examples of biological data. Keep in mind that we are discussing how to analyze biological data. One of the most basic ways to begin such analysis is to calculate the mean for the data you've gathered.
If someone asks, "How much do seventh graders weigh?" the most meaningful answer is probably the mean weight of seventh graders. If we weigh 40 seventh graders there is a good chance that the heaviest one will weigh somewhere around 140 pounds and the lightest one will weigh around 70 pounds. As you can see the heaviest one is likely to be twice as heavy as the lightest one. The average weight of seventh graders is probably going to be somewhere around 98 pounds (which is not exactly half way between 70 and 140). (NOTE: In the case of seventh graders it would probably be appropriate to report separate means for each gender.)
Likewise, in the case of reporting the time to recovery after beginning treatment with some therapeutic agent, it makes the most sense to report the average time to recovery. For instance, you might have one patient recover in 13 days after beginning treatment and another not recover until 31 days after starting treatment (and some patients might not respond at all), but the most meaningful single statistic is the mean time to recovery which might be something like 26 days (which is definitely not exactly half way between 13 and 31).
We have limited this discussion to the arithmetic mean. Obviously, the mean or average is not the only statistic we can generate from a data set. We will discuss more statistics in upcoming lessons.
Calculating the Mean
To calculate the mean we simply add up all the values in our data set and then divide this total by the total number of values in the set. This can be summarized like this:
ASSIGNMENT:
Write a PERL script which calculates the average for twelve values. Your values must range between 60 and 110 and be more or less (approximately) evenly distributed within this range. Format your output like this: