A function line_averages(filename) that takes a string filename which contains the name of a file to be processed. The function should open and read that file. The file is expected to contain numbers that are separated by commas (the format is known as a comma-separated-value file, short csv). The function should compute the average value for every line, and return the average values in a list. For example, if we call line_averages("data.csv") and file data.csv reads:
1,2
1,1,1,1
-1,0,1
42,17
then the function should return the list [1.5, 1.0, 0.0, 29.5].
The library urllib.request allows to access a webpage like a file
through its urlopen() function, and you should include import
urllib.request at the beginning of your file training4.py.
Call the function noaa_string from the Python prompt and
inspect the return value.
Your task is to write a function noaa_temperature(s) which should
take a string s as returned from noaa_string() as the input
argument, extract the temperature in degree Celsius from the
string, and return this temperature as an integer number:
In [ ]: noaa_temperature(noaa_string())
Out[ ]: 10
NOAA may at times change the number and order of lines in the data,
but you can assume that the format of the line containing the
temperature data does not change.
A function seq_sqrt(xs) which takes a list of non-negative
numbers xs with elements [x0, x1, x2, ..., xn], and returns
the list [sqrt(x0), sqrt(x1), sqrt(x2), ..., sqrt(xn)]. In
other words, the function takes a list of numbers, and returns a
list of the same length that contains the square root for each
number in the list.
A function mean(xs) that takes a sequence xs of numbers, and returns the (arithmetic) mean (i.e. the average value).
Example:
In [ ]: mean([0, 1, 2])
Out[ ]: 1.0
A function wc(filename) that returns the number of words in file
filename. The name wc stands for Word Count. To split a string s into words, use s.split() for this
exercise (i.e. the behaviour of the split() method is here used to define what a word
is).