Assignment
Q1 Finding the average weather temperature ( coded temperatures, for example, the mean could have been subtracted from each actual temperature)
Scenario: Given a list of weather temperatures in fahrenheit coded as follows:
weatherF = [ 1, 3, 1, 5, 3, 3, 2, 1, 1, 4, 4 ,4, 1, 1, 1 ] # note these are the ‘coded' temperatures
Write the Python code to calculate the average temperature for the weatherF list, doing it two ways. Use the ‘len' function to get the length of an array, don't manually count. Use this ‘len' function to determine maxIndex as well as the denominator for the average calculation. Avoid magic numbers..
A: Write a Python program to calculate the average temperature using a while loop and using indexes to get the element temperatures
Print out the temperature at each iteration. Print the average temperature after the loop terminates.
B: Write a Python program to calculate the average temperature using a for loop
Print out the temperature at each iteration. Print the average temperature after the loop terminates.
Q2 : Finding the frequency distribution of the temperatures
Write a Python program to find the frequency distribution of the temperatures.
That is, weatherF is a list of temperatures: how many times does the temperature value of ‘1' occur? Manually, I can see it occurs 7 times, but I want to automate that analysis.
To start off, name your frequency distribution list as frequencyDistribution.
Hints: How many different values of elements must it hold? That will be its size.
The frequencyDistribution[0] element should be ‘7', that is, there are ‘7' ones. What should the other indices hold?
Use a for loop to go through weatherF list, and for each element encountered, bump the contents of the frequencyDistribution array index holding that element ‘s value. That is, for example, frequencyDistribution[0] ‘s contents will be bumped 7 times, which equals the number of ‘1' s encountered.
Q3 : Write a Python program to find the max and min of the weatherF list. Print those out at the termination of the loop. ( use either style you like)
Use constants to represent the initial max and min values.
Q4 : Write the Python function that accepts a list of numerics as an argument and returns the average of the list elements. Note, this is a generalization of what you did in question Q1. Now the list is just a list of numbers. Hint, use the ‘len' function to determine the denominator for the aver.