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
Temperature variations
You will learn about: statistics and summing lots of numbers.
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 | ||
---|---|---|---|
Maximum runtime | 60 s | Max. memory usage | 250 MiB |
Function signature | temperature_statistics(T) |
Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.
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. Feel free to post your solutions but if you do please organize and document your code well so others can learn from it.