Example
Input temperatures: [4.4, 4.2, 7.0, 12.9, 18.5, 23.5, 26.4, 26.3, 22.5, 16.6, 11.2, 7.3]
Output mean: 15.067
Output standard deviation: 8.021
If you live in the tropics, in the rainforest, near the equator or on an island, the temperature doesn't change a huge amount throughout the year. But if you live in the subtropics or temperate zones then you probably get big swings in temperatures between winter and summer. We can use the average and standard deviation to say things about the climate of a city.
The average (or mean) temperature tells us how warm or cold a place is, while the temperature standard deviation tells us how much the temperature varies. For a series of temperature observations $T_1, T_2, \dots, T_n$, the average temperature $\overline{T}$ is calculated as $$ \overline{T} = \frac{T_1 + T_2 + \cdots + T_n}{n} = \frac{1}{n} \sum_{i=1}^n T_i $$ which can then be used to calculated the temperature standard deviation $\sigma_T$ using $$ \sigma_T = \sqrt{\frac{(T_1 - \overline{T})^2 + (T_2 - \overline{T})^2 + \cdots + (T_n - \overline{T})^2}{n}} = \sqrt{\frac{1}{n} \sum_{i=1}^n (T_i - \overline{T})^2} $$
Input: A list of temperatures in degrees Celsius.
Output: The average temperature, and the temperaure standard deviation.
Difficulty | Timesink | ||
---|---|---|---|
Function | temperature_statistics(T) |
You must be logged in to view your submissions.
Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.