The purpose of this mini-lab is to practice creating and working with arrays in Python to process temperature data.
import numpy as np
This statement will allow us to use the functions in this
module.avgTemp
that takes
an array of temperature values as a parameter and calculates
the average value of the elements in the array. To
calculate the average, your function should add up all of
the array values and then divide by the number of elements
in the array. (Note: You should not assume
your array has 31 values, but rather, use the
len
of the array to get the size.) Your
function should then return the average value.print("The average high temp from
Aug 2021 is: ", avgTemp(aug2021HighArray))
.
Double check your results by calculating the average with a
calculator.medianTemp
that
takes an array of temperature values as a parameter and
returns the median value of the array. To find the median
value, you should first sort the array (use the sort
function from NumPy), and then return the middle element of
the sorted array.maxTemp
that takes
an array of temperatures as a parameter and calculates the
maximum value of the array. It should return the maximum value. To
calculate the maximum value, create a variable, call it
maxValue
, that gets initialized to the first
value in the array. Then use a for loop
to go
through the elements in the array. Inside the loop, you
should use an if statement
to compare the
current array element with what you have for the
maxValue
so far. Update maxValue
if the current array element is larger. When the loop is
finished, return the maximum value.maxTemp
function with each of
your arrays and print the value that get returned. Include
text with your printed statement to indicate what year you
are reporting on, as in print("Max low temp for the month of August in
the year 2005 is: " ,
maxTemp(aug2005LowArray))
.minTemp
that
returns the minimum value from an array of temperature
values. The code for this function will be quite similar to
that for the maxTemp
function.numGreaterThan
that
takes an array of temperature values and a specific value as
parameters, and returns the number of temperature values
that are greater than the specifed value. To do this,
create a variable called count
that is
initially 0. Loop through the array and check if each value
is greater than the specified value. If it is, increment
count
by 1. Return the count at the end of the
function.numLessThan
that
takes an array of temperature values and a specific
value as parameters, and returns the number of
temperature values that are less than the specified
value.