lab4-extra¶
seq_sqrt(xs)
¶
A function seq_sqrt(xs)
which takes a list of non-negative numbers
xs
with elements \([x_0, x_1, x_2, \ldots, x_n]\), and returns
the list
\([\sqrt{x_0}, \sqrt{x_1}, \sqrt{x_2}, \ldots, \sqrt{x_n}]\). 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.
Examples:
In [ ]: seq_sqrt([1, 2, 3])
Out[ ]: [1.0, 1.4142135623730951, 1.7320508075688772]
In [ ]: seq_sqrt([1, 4, 9])
Out[ ]: [1.0, 2.0, 3.0]
wc(filename)
¶
Write 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).
Example 1: For a file data.txt
with content:
One Two
a function call wc('data.txt')
should return 2
.
Example 2: For a file data.txt
with content:
One Two
Three Four Five
a function call wc('data.txt')
should return 5
.
You can test your function on the Alice in Wonderland book and should expect that this has more than 10,000 words.
(If you use Linux or OSX, you can download a file offered at a URL using
wget URL
from the a terminal. For this example, try
wget https://www.gutenberg.org/files/19033/19033.txt
).
Please include the extra tasks in your file lab4.py
and submit as Computing lab4 assignment.
Back to lab4.
End of lab4-extra.