Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

). # # ### Problem A1, Loading Cow Data # # First we need to load the cow data from the data file `ps1_cow_data.txt`. #

). #

# ### Problem A1, Loading Cow Data # # First we need to load the cow data from the data file `ps1_cow_data.txt`. # # The file `ps1_cow_data_2.txt` is given as another file that you can read and test from (You are encouraged to write your own cow list files for testing!), but for now, just work with `ps1_cow_data.txt` # # You can expect the data to be formatted in pairs of x,y on each line, where x is the name of the cow and y is a number indicating how much the cow weighs in tons. Here are the first few lines of `ps1_cow_data.txt`: # # Maggie,3 # Herman,7 # Betsy,9 # # You can assume that all the cows have unique names. # # #### Hint: # # If you dont remember how to read lines from a file, check out the online python documentation, which has a chapter on Input and Output that includes file I/O here: https://docs.python.org/3/tutorial/inputoutput.html # # Some functions that may be helpful: # - `str.split` # - `open` # - `file.readline` # - `file.close`

# In[ ]:

def load_cows(filename): """ Read the contents of the given file. Assumes the file contents contain data in the form of comma-separated cow name, weight pairs, and return a dictionary containing cow names as keys and corresponding weights as values.

Parameters: filename - the name of the data file as a string

Returns: a dictionary of cow name (string), weight (int) pairs """ # TODO: Your code here pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

5. Recognize your ability to repair and let go of painful conflict

Answered: 1 week ago