Peter,1000
Joan,50500
Mary,2400Module 9 Assignments
Short Project 07
Short Programming projects are submitted during our weekly 45-minute in-person lab sessions. Each lab sessions is guided by two TAs. The instructions for the short project will be available only during the lab sessions. To schedule your lab session go to the weekly lab session spreadsheet in Short Project Dates and Instructions.
Programming Problems
Programming Problems should be submitted to gradescope.
Programming Problem 17
Due date: Friday, March 28, 2025 at 9pm
Write a Python function that does the following:
- Its name is
read_csv - It takes a string as argument called
file_name - It opens the file with
file_namein read mode - It iterates over each line in the file, splitting each line by
"," - It creates a dictionary where the keys are the first item in each line, and the values are the other values (in a list)
- It returns the dictionary
Test cases:
contents of stipends.csv:
print( read_csv("stipends.csv") ) # {"Peter": [1000],
# "Joan": [50500],
# "Mary": [2400]}contents of population.csv:
Country,United States,Brazil,Mexico,Canada
Population (in mil),331.00,212.56,128.93,37.74print( read_csv("population.csv") ) # {"Country": ["United States", "Brazil", "Mexico", "Canada"],
# "Population (in mil)": [331.00, 212.56, 128.93, 37.74]}Name the program read_data_file.py. Make sure that gradescope gives you the points for passing the test case.
Programming Problem 18
Due date: Friday, March 28, 2025 at 9pm
Write a Python function that does the following:
- Its name is
write_csv - It takes a
dictionaryand a stringfile_nameas arguments - It opens the file with
file_namein write mode - It iterates over the
dictionaryto write lines to the opened.csv - Each key is the first element of the line, the values are lists that contain the other values in the line
Test cases:
my_data = {"Peter": [1000], "Joan": [50500], "Mary": [2400]}
write_csv(my_data, "stipends.csv")This is what stipends.csv should contain:
Peter,1000
Joan,50500
Mary,2400my_data = {"Country": ["United States", "Brazil", "Mexico", "Canada"],
"Population (in mil)": [331.00, 212.56, 128.93, 37.74]}
write_csv(my_data, "population.csv")This is what population.csv should contain:
Country,United States,Brazil,Mexico,Canada
Population (in mil),331.0,212.56,128.93,37.74Name the program write_data_file.py. Make sure that gradescope gives you the points for passing the test case.