-
mult( n, m )
should output the product of the two integers n
and m
. Since this would be a bit too easy if the multiplication operator * were used, for this function, you are limited to using addition/subtraction/negation operators, along with recursion. (Use the power
function we
did in class as a guide.) Some examples:
>>> mult( 6, 7 )
42
>>> mult( 6, -3 )
-18
-
dot( L, K )
should output the dot product of the lists L
and K
. If these two input lists are not of equal length, dot
should output 0.0
. If these two lists are both empty, dot
also should output 0.0
. You should assume that the input lists contain only numeric values. (Compare this with the mysum
example we did in class, but be sure to use both lists...!) Recall that the dot product of two vectors or lists is the sum of the products of the elements in the same position in the two vectors. for example, the first result is 5*6
plus 3*4
, which is 42. The result here is 42.0, because we used a float
of 0.0 in the base case!
>>> dot( [5,3], [6,4] )
42.0
>>> dot( [1,2,3,4], [10,100,1000,10000] )
43210.0
>>> dot( [5,3], [6] )
0.0
-
Write
ind(e, L)
, which takes in a sequence L
and an element e
. L
might be a string or, more generally, a list. Your function ind
should return the index at which e
is first found in L
. Counting begins at 0, as is usual with lists. If e
is NOT an element of L
, then ind(e, L)
should return any integer larger than or equal to len(L)
. It can be len(L)
exactly, as shown below in these examples:
>>> ind(42, [ 55, 77, 42, 12, 42, 100 ])
2
>>> ind(42, range(0,100))
42
>>> ind('hi', [ 'hello', 42, True ])
3
>>> ind('hi', [ 'well', 'hi', 'there' ])
1
>>> ind('i', 'team')
4
>>> ind(' ', 'outer exploration')
5
- letterScore( let ) should take as input
a single-character string and produce as output
the value of that character as a scrabble tile.
If the input is not one of the letters from 'a'
to 'z', the function should return 0.
To write this function you will need to
use this mapping of letters to scores

What!? Do I have to write 25 or 26 if elif or else statements?
No! Instead, use the in keyword:
>>> 'a' in 'this is a string including a'
True
>>> 'q' in 'this string does not have the the letter before r'
False
Phew!
This letterScore does not require recursion. But recursion is used in the next one... .
- scrabbleScore( S ) should take as input
a string S, which will have only lowercase letters,
and should return as output
the scrabble score of that string. Ignore the fact
that, in reality, the availability of each letter tile
is limited. Hint: use the above letterScore
function and recursion. (Compare this with the the
mylen
example
we did in class.)
Here are some examples:
>>> scrabbleScore('quetzal')
25
>>> scrabbleScore('jonquil')
23
>>> scrabbleScore('syzygy')
25