HW4 Weather
HW4 Weather
CS 230
Introduction to Programming with Python
DATA
A zip file, weather_data.zip, containing the data files is provided. Unzip this file and place the
unzipped folder weather_data into your project folder, where your program file will be placed.
Review the content of the folders with data – you will notice that each folder has:
• A file named us_states.txt with all US states, the format is as following shows where the
first column is the state full name and the second column is the abbreviation.
Alabama, AL
Alaska, AK
Arizona, AZ
Arkansas, AR
California, CA
Colorado, CO
Connecticut, CT
Delaware, DE
Florida, FL
Georgia, GA
1
Bentley University Fall 2024
CS 230
Introduction to Programming with Python
data for various cities. The four columns are City Name, State Name/Abbreviation,
Average Temperature, and Average Humidity of the city, respectively.
El Paso, TX, 63.8 F, 88.3%
Detroit, Michigan, 52.5 F, 56.3%
Nashville, Tennessee, 91.4 F, 60.5%
Memphis, TN, 64.0 F, 47.7%
Review the contents and structure of these files to gain a good understanding of them.
IMPLEMENTATION
A starter file, weather-starter.py, is provided for you to begin with. Rename it as weather.py.
To produce the desired output, the program needs to perform the following steps:
1. Reading the State Info File:
• The program begins by reading the us_states.txt file, which contains the full names and
abbreviations of all U.S. states.
• Function: read_states(file_path)
o The read_states function takes the file path (“./weather_data”) containing the
us_states.txt file as an argument.
o Opens the us_states.txt file and reads each line, splitting the full state name and its
abbreviation.
o Creates and returns a dictionary state_dict that associates state abbreviations with
their full names.
o The following is an example for the returned dictionary (the following example only
contains part of the state information, the real dictionary should contain all the state
information)
▪ state_dict:
2
Bentley University Fall 2024
CS 230
Introduction to Programming with Python
'AverageTemperature': 88.8,
'MaxHumidity': 85.8,
'MaxTemperature': 88.8,
'MinHumidity': 85.8,
'MinTemperature': 88.8}}
4. User Input and Information Display:
• The program prompts the user to enter one or more state names or abbreviations (in any case
format) to display the weather statistics.
• Function: show_weather_information(states, weather_stats, state_dict)
o The program collects user input and splits it into a list of states (which can be full names
or abbreviations in any case format).
o This function is called with the list of user-input states, the weather_stats dictionary,
and the state dictionary state_dict.
o It normalizes the user input to handle case insensitivity and uses the dictionaries to
convert abbreviations to full names (or vice versa) as needed.
o Looks up the statistics for each requested state from the weather_stats dictionary.
o Prints the weather statistics (maximum, minimum, and average temperature and
humidity) for each specified state using f-string. The temperatures and humidity levels
should be with 2 decimal points. If the files do not contain the states requested, show
“No data available” for the states at the end of the output.
o Sample output
4
Bentley University Fall 2024
CS 230
Introduction to Programming with Python
REQUIREMENTS
• Replace pass in each function in the starter file with your own code.
• You DO NOT need to worry about incorrect input in this assignment. Your program will be tested
only with valid data.
• Your program may be tested on other data, so do not hardcode the input and output.
• You are prohibited from using any other Python libraries or packages that are not covered in this
class.
• The use of artificial intelligence programs to generate code or other content is strictly
prohibited. You will receive a grade of 0 and an Academic Integrity Violation for any assignments
that appear to be produced using AI tools.
HINTS
• When debugging our code, you may insert print function to print out variable values.
• When printing values of dictionaries, you can use the prettyprint module (pprint) to display the
dictionaries in an easier-to-read format. Try this program as a sample:
import pprint as pp
dict = {'California': {'temperatures': [99.1, 51.5, 75.7, 83.7],
'humidities': [50.7, 87.0, 55.2, 89.2]}, 'North Carolina':
{'temperatures': [88.8], 'humidities': [85.8]}, 'Indiana':
{'temperatures': [61.6], 'humidities': [51.8]}}
pp.pprint(dict)
Output:
SUBMISSION
Test your program to make sure it works. Submit weather.py file on Brightspace.
Do not submit other files.
GRADING
5
Bentley University Fall 2024
CS 230
Introduction to Programming with Python
• Your program should compile without syntax errors to receive any credit. If a part of your program is
working, you will receive partial credit, but only if the program compiles without syntax errors. Your
grade will be zero on this assignment if it contains any syntax errors.
Rubrics Points
Correctly implementing each function according to the specification 43
• read_states 3
• read_weather_files 15
• calculate_weather_statistics 10
• show_weather_information 10
• main 5
Having no code outside of function definitions except for a call to main(), and
5
no global variables
Programming style: including docstring, intro comments to functions,
2
descriptive variable names, etc.
Total 50