10 total points
Directions¶
- Due: 10/12/2025 @ 11:59 p.m.
- Change the name of your notebook to HW2_FirstLast.ipynb, where First is your first name and Last is your last name.
- For each of the following prompts, write or modify Python code that fulfills the requirements.
Important information to remember¶
- Periodically, you should click File -> Save Notebook
- When you are done working for the day, click File -> Log Out
- When you are finished, download the notebook and upload it to the submission link
- I will reset the notebook and run each code block on its own. You will receive half credit if you rely on a variable from a previous or subsequent code block.
Problem Statement¶
You will be using the following average monthly high temperature data for the DeKalb station and calculating normals, extremes, and frequencies.
YEAR | JAN | FEB | MAR | APR | MAY | JUN | JUL | AUG | SEP | OCT | NOV | DEC |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1991 | 26 | 37.7 | 49.4 | 63.8 | 70 | 85.7 | 86.1 | 85.2 | 74.9 | 61.7 | 41.5 | 35.9 |
1992 | 32.2 | 38 | 46.3 | 54.4 | 71.9 | 79.8 | 78.6 | 76.9 | 72.4 | 62 | 42.6 | 34 |
1993 | 30.2 | 30.6 | 40.7 | 55 | 73.1 | 77.1 | 82.4 | 81.9 | 75.1 | 61.4 | 44.3 | 33 |
1994 | 21.5 | 27.6 | 45.5 | 62.3 | 71.9 | 84.6 | 83.2 | 78.7 | 75.2 | 64.1 | 49.8 | 37 |
1995 | 27.4 | 32.2 | 48.1 | 54.3 | 67.1 | 83.7 | 86.8 | 87.7 | 72.4 | 63 | 37.6 | 31.2 |
1996 | 27.6 | 32 | 38.9 | 56.6 | 64.9 | 78.4 | 79.8 | 80.7 | 71.8 | 62.3 | 36.6 | 30 |
1997 | 23.4 | 32.3 | 45.5 | 54.4 | 63.8 | 80 | 83.1 | 78 | 74.6 | 62.3 | 41.1 | 32.6 |
1998 | 31.9 | 42.2 | 44 | 58.4 | 75.4 | 78.5 | 82.7 | 82.1 | 79 | 63.3 | 50.3 | 41.4 |
1999 | 24.9 | 39.5 | 43.3 | 59.7 | 72.5 | 80.5 | 86.9 | 78.6 | 74.3 | 63.5 | 56.4 | 33.8 |
2000 | 29 | 38.3 | 54 | 58.7 | 72.2 | 76.3 | 80 | 80.8 | 75.1 | 66.3 | 42.6 | 21.2 |
2001 | 27.7 | 30.4 | 41.3 | 63.7 | 72 | 77 | 85 | 83.2 | 72 | 60.1 | 57.4 | 39 |
2002 | 36.3 | 37.5 | 41.9 | 57.5 | 64.3 | 81.3 | 87.1 | 82.7 | 78.9 | 58.2 | 43.2 | 35.8 |
2003 | 25.6 | 30.2 | 44.9 | 59.9 | 67 | 77 | 82.5 | 84.7 | 74.1 | 62.7 | 48.4 | 36.8 |
2004 | 24.3 | 33.1 | 49 | 61.7 | 71 | 77.1 | 79.4 | 75.8 | 78.2 | 62.9 | 49.1 | 33.2 |
2005 | 29 | 37.3 | 42.7 | 64.6 | 67.6 | 85.3 | 85 | 83.8 | 80.5 | 64.5 | 47.7 | 25.8 |
2006 | 38.5 | 34.7 | 44.6 | 64.2 | 69.1 | 78.1 | 84.5 | 81.7 | 71 | 57.2 | 49.3 | 36.5 |
2007 | 32.4 | 22.2 | 49.4 | 55.6 | 76.2 | 79.8 | 81.9 | 82.4 | 79.2 | 68.5 | 46.3 | 29.6 |
2008 | 28.8 | 26 | 39.8 | 58.3 | 66.9 | 80 | 82.4 | 80.2 | 74 | 60.4 | 45.7 | 29 |
2009 | 19.8 | 33.9 | 46.6 | 56.8 | 70 | 78.3 | 76.1 | 76.6 | 74.1 | 54.2 | 51.8 | 30 |
2010 | 23.9 | 29.8 | 48.7 | 66.8 | 71.8 | 80.3 | 85.3 | 83.9 | 74.6 | 67.3 | 49.8 | 24.2 |
2011 | 24.7 | 30 | 43.2 | 55 | 69.2 | 79.7 | 86.9 | 81.7 | 70 | 64.3 | 49.4 | 38.5 |
2012 | 34 | 37.3 | 61.1 | 59.5 | 75.9 | 82.1 | 89.8 | 82.8 | 74.9 | 59.7 | 46.7 | 39.5 |
2013 | 32.4 | 29.6 | 35.4 | 54.6 | 72.9 | 77.3 | 81.1 | 81.1 | 75.2 | 61.3 | 43.4 | 28.1 |
2014 | 20.6 | 20.7 | 35.9 | 58.6 | 69.7 | 80.1 | 77.9 | 80.4 | 74 | 60.5 | 38.7 | 35.8 |
2015 | 26.4 | 21.5 | 42.5 | 61.7 | 70.7 | 76.7 | 80.1 | 79.1 | 78.5 | 63.2 | 50.8 | 42.9 |
2016 | 27.4 | 34.9 | 50.2 | 58.3 | 69.7 | 81.3 | 82.2 | 82.7 | 78.2 | 65.6 | 54.9 | 28.3 |
2017 | 32 | 44.7 | 45.4 | 61.6 | 66.3 | 81.1 | 81.4 | 78.7 | 78.6 | 63.9 | 44.1 | 32.1 |
2018 | 27.9 | 31.9 | 44 | 49.1 | 76.5 | 79.5 | 82.7 | 82.3 | 77.6 | 58.2 | 37.5 | 36.4 |
2019 | 26.5 | 29.1 | 40.8 | 57.2 | 65.8 | 77.5 | 86.3 | 80.2 | 75.1 | 59.2 | 38.8 | 39.4 |
2020 | 32.4 | 32.6 | 46.4 | 55.1 | 67.1 | 82.6 | 84.6 | 82.2 | 72 | 57.6 | 53 | 37.2 |
I have conveniently converted the columns into Python lists
for you to use in your code. Only the lists ([ ]) and the values inside them are valid Python code:
January data = [26.0, 32.2, 30.2, 21.5, 27.4, 27.6, 23.4, 31.9, 24.9, 29.0, 27.7, 36.3, 25.6, 24.3, 29.0, 38.5, 32.4, 28.8, 19.8, 23.9, 24.7, 34.0, 32.4, 20.6, 26.4, 27.4, 32.0, 27.9, 26.5, 32.4]
February data = [37.7, 38.0, 30.6, 27.6, 32.2, 32.0, 32.3, 42.2, 39.5, 38.3, 30.4, 37.5, 30.2, 33.1, 37.3, 34.7, 22.2, 26.0, 33.9, 29.8, 30.0, 37.3, 29.6, 20.7, 21.5, 34.9, 44.7, 31.9, 29.1, 32.6]
March data = [49.4, 46.3, 40.7, 45.5, 48.1, 38.9, 45.5, 44.0, 43.3, 54.0, 41.3, 41.9, 44.9, 49.0, 42.7, 44.6, 49.4, 39.8, 46.6, 48.7, 43.2, 61.1, 35.4, 35.9, 42.5, 50.2, 45.4, 44.0, 40.8, 46.4]
April data = [63.8, 54.4, 55.0, 62.3, 54.3, 56.6, 54.4, 58.4, 59.7, 58.7, 63.7, 57.5, 59.9, 61.7, 64.6, 64.2, 55.6, 58.3, 56.8, 66.8, 55.0, 59.5, 54.6, 58.6, 61.7, 58.3, 61.6, 49.1, 57.2, 55.1]
May data = [70.0, 71.9, 73.1, 71.9, 67.1, 64.9, 63.8, 75.4, 72.5, 72.2, 72.0, 64.3, 67.0, 71.0, 67.6, 69.1, 76.2, 66.9, 70.0, 71.8, 69.2, 75.9, 72.9, 69.7, 70.7, 69.7, 66.3, 76.5, 65.8, 67.1]
June data = [85.7, 79.8, 77.1, 84.6, 83.7, 78.4, 80.0, 78.5, 80.5, 76.3, 77.0, 81.3, 77.0, 77.1, 85.3, 78.1, 79.8, 80.0, 78.3, 80.3, 79.7, 82.1, 77.3, 80.1, 76.7, 81.3, 81.1, 79.5, 77.5, 82.6]
July data = [86.1, 78.6, 82.4, 83.2, 86.8, 79.8, 83.1, 82.7, 86.9, 80.0, 85.0, 87.1, 82.5, 79.4, 85.0, 84.5, 81.9, 82.4, 76.1, 85.3, 86.9, 89.8, 81.1, 77.9, 80.1, 82.2, 81.4, 82.7, 86.3, 84.6]
August data = [85.2, 76.9, 81.9, 78.7, 87.7, 80.7, 78.0, 82.1, 78.6, 80.8, 83.2, 82.7, 84.7, 75.8, 83.8, 81.7, 82.4, 80.2, 76.6, 83.9, 81.7, 82.8, 81.1, 80.4, 79.1, 82.7, 78.7, 82.3, 80.2, 82.2]
September data = [74.9, 72.4, 75.1, 75.2, 72.4, 71.8, 74.6, 79.0, 74.3, 75.1, 72.0, 78.9, 74.1, 78.2, 80.5, 71.0, 79.2, 74.0, 74.1, 74.6, 70.0, 74.9, 75.2, 74.0, 78.5, 78.2, 78.6, 77.6, 75.1, 72.0]
October data = [61.7, 62.0, 61.4, 64.1, 63.0, 62.3, 62.3, 63.3, 63.5, 66.3, 60.1, 58.2, 62.7, 62.9, 64.5, 57.2, 68.5, 60.4, 54.2, 67.3, 64.3, 59.7, 61.3, 60.5, 63.2, 65.6, 63.9, 58.2, 59.2, 57.6]
November data = [41.5, 42.6, 44.3, 49.8, 37.6, 36.6, 41.1, 50.3, 56.4, 42.6, 57.4, 43.2, 48.4, 49.1, 47.7, 49.3, 46.3, 45.7, 51.8, 49.8, 49.4, 46.7, 43.4, 38.7, 50.8, 54.9, 44.1, 37.5, 38.8, 53.0]
December data = [35.9, 34.0, 33.0, 37.0, 31.2, 30.0, 32.6, 41.4, 33.8, 21.2, 39.0, 35.8, 36.8, 33.2, 25.8, 36.5, 29.6, 29.0, 30.0, 24.2, 38.5, 39.5, 28.1, 35.8, 42.9, 28.3, 32.1, 36.4, 39.4, 37.2]
You can only use the following functions to perform your calculations. Functions for list
, dict
, and str
are also allowed.
max(my_list)
- finds the maximum value inmy_list
.Example:
my_list = [1, 2, 3, 4] max_in_list = max(my_list) print(max_in_list) # prints 4
min(my_list)
- finds the minimum value inmy_list
.Example:
my_list = [1, 2, 3, 4] min_in_list = min(my_list) print(min_in_list) # prints 1
sum(my_list)
- finds the sum of values inmy_list
.my_list = [1, 2, 3, 4] sum_of_list = sum(my_list) print(sum_of_list) # prints 10
len(my_list)
- finds the number of values inmy_list
.my_list = [0, 5, 10, 51, 25] count_in_list = len(my_list) print(count_in_list) # prints 5
Extra Requirements
Because I want you to learn the basics of Python, you must abide by the following rules. Failure to do so will result in no points earned for that task:
- You cannot use an “imported” Python package (numpy, pandas, etc.).
- You cannot use any loop except a dictionary iterator.
- You cannot “hard code” a value in your calculation. You may be tempted to manually calculate the sums, counts, etc., and place that number in the code. For example:
normal = 1051 / 30
temp = 1051
day = 30
normal = temp / day
Both 1051
and 30
are violations of this rule. temp
and day
are also violations in the example because you manually placed the numbers. You must use one of the functions above to get a result and use it in your calculation.
Summary of HW2 Tasks¶
Task 1 (2 points) - Generate a data dictionary¶
Convert the table above into a dict
with the following keys:
“YEAR” “JAN” “FEB” “MAR” “APR” “MAY” “JUN” “JUL” “AUG” “SEP” “OCT” “NOV” “DEC”
Each key should be associated with a list
that has 30 float
values associated with the observed high temperatures from the table above.
For example, the “YEAR” key would be associated with this list
:
[1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014, 2015,
2016, 2017, 2018, 2019, 2020]
You must use a dictionary with string keys and lists for your dictionary values.
Task 2 (2 points) - Extremes¶
Use dictionary indexing to calculate the minimum and maximum monthly temperatures in the table.
Use the following template to print statistics for all 12 months:
“The average monthly high temperature for JAN ranged from a minimum of XX.XX F to a maximum of XX.XX F”
“The average monthly high temperature for FEB ranged from a minimum of XX.XX F to a maximum of XX.XX F”
etc.
You must insert a variable for the month and the min and max average temperatures using f-strings.
You must use max
, min
, sum
, or length
(you can use all four if needed) to get numerical values for your equation. Hard coded numbers will result in no points (see above).
Task 3 (3 points) - Frequency¶
Use dictionary indexing to count how many months had an average monthly high temperature that exceeded 80 F.
Use the following example template to print statistics:
“There were 12 months that had a monthly average temperature above 20 F. These months were JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC.”
You must insert a variable for the count of months and the names of each month. The names of the months must actually be months that had a high temperature that exceeded 80F. You cannot manually add qualifying months (hard coding). For example, the following code will get you no credit:
qualifying_months = ['JAN', 'JUN', 'OCT']
You must use max
, min
, sum
, or length
(you can use all four if needed) to get numerical values for your equation. Hard coded numbers will result in no points (see above).
To get you started, I provided some code:
qualifying_months = []
### Your code that loops through a dictionary
### if criteria met, add the month to qualifying_months. Otherwise, do nothing.
Task 4 (3 points) - Normals¶
Use a dictionary iterator to calculate the average temperature for each month (30-yr climate normal).
You need to use the following template to print out all 12 monthly values:
“The average high temperature for JAN from 1991 - 2020 was XX.XX F”
“The average high temperature for FEB from 1991 - 2020 was XX.XX F”
etc.
You must insert a variable for the month and the average temperature using f-strings.
You must use max
, min
, sum
, or length
(you can use all four if needed) to get numerical values for your equation. Hard coded numbers will result in no points (see above).