Starting from:

$24.99

Homework 7 Dictionaries

 Homework 7 Dictionaries
Problem Description
Write a program that reads a certain month from the user (an index between 1 and 12), and find the data for this month in each year to print out the following information:
• Top 3 years and associated values for:
– highest maximum temperature (EMXT) – lowest minimum temperature (EMNT) – highest number of days with maximum temperature above 90 (DT90) – highest number of days with maximum temperature below 32 (DX32) – highest total precipitation (TPCP) – lowest total precipitation (TPCP) – highest snow depth (TSNW) – lowest snow depth (TSNW)
If there are less than 3 values above zero for a given parameter for that month, then print that there is not enough data (for example snow depth in August!). • Average of mean temperature across different years (MNTM)
– Overall average (average of all years for MNTM) – Average for the first 10 years we have data for (for MNTM) – Average for the last 10 years we have data for (for MNTM) • A histogram of (integer part of) overall average temperatures in 10 year increments (plus the last remaining years after counting by 10s), print a single star for each degree. Note that the histogram should disregard missing values.
Hint. Just a few hints on how to proceed in solving this homework. It sounds like there are many things to compute, but it is actually the same thing for many different keys of the same dictionary. My program is 100 lines, it basically has two main functions. The first function loops through through the dictionary for any given month and key (both parameters to my function) and computes all the above statistics, and returns them in a dictionary. Then, in my program, I simply need to print these values. As all the above computation really uses the same set of value and year pairs, this saves a lot of repetition. In this dictionary, I even return the list of values. I have a second function for printing the histogram of a set of values. I can simply use the dictionary returned by the first function to find the values, and then use them to print the histogram. This is a good homework to fully make use of generic functions and dictionaries to help you solve many different problems. Start with one function to print the first line of the output (for EMXT), then think about how to generalize it to solve all the other parts quickly.
Expected output
Below you can see the expected functioning of this program with the file we gave you (note: we might change the file in the homework submission server):
Enter a month (1-12) = 11 11 Temperatures -------------------------------------------------Highest max value = 1975: 83.0, 1982: 81.0, 1956: 80.0 Lowest min value = 1958: 10.0, 1996: 10.0, 1957: 12.0 Highest days with max = 90 = Not enough data Highest days with max <= 32 = 1989: 4.0, 2013: 3.0, 2005: 3.0
Precipitation -------------------------------------------------Highest total = 1972: 6.9, 1969: 6.8, 1959: 6.3 Lowest total = 2011: 0.4, 1978: 0.7, 2012: 0.9 Highest snow depth = 1971: 22.5, 1972: 19.0, 1985: 11.5 Lowest snow depth = 2000: 0.1, 1962: 0.3, 2013: 0.5
Average temperatures -------------------------------------------------Overall: 41.0 First 10 years: 41.4 Last 10 years: 41.2
1956-1965: ***************************************** 1966-1975: **************************************** 1976-1985: ***************************************** 1986-1995: **************************************** 1996-2005: ***************************************** 2006-2014: *****************************************
Enter a month (1-12) = 7 7 Temperatures -------------------------------------------------Highest max value = 1995: 101.0, 2010: 99.0, 1988: 99.0 Lowest min value = 1963: 45.0, 1960: 46.0, 1961: 46.0 Highest days with max = 90 = 1988: 14.0, 2010: 12.0, 1983: 12.0 Highest days with max <= 32 = Not enough data
Precipitation -------------------------------------------------Highest total = 1984: 9.4, 2004: 8.7, 2009: 8.4 Lowest total = 1964: 1.1, 2002: 1.4, 1977: 1.9 Highest snow depth = Not enough data Lowest snow depth = Not enough data
Average temperatures -------------------------------------------------Overall: 73.0 First 10 years: 72.0 Last 10 years: 73.9
1957-1966: ************************************************************************ 1967-1976: ************************************************************************* 1977-1986: ************************************************************************* 1987-1996: ************************************************************************* 1997-2007: ************************************************************************ 2008-2014: **************************************************************************

More products