Lecture 27:

posted Mar 12, 2013, 6:12 AM by Samuel Konstantinovich   [ updated Mar 15, 2013, 5:35 AM ]
Goal: To use list methods

Lets see how we can write these functions: (complete at home)
1. sumList(L) a function that takes a list of integers as a parameter, and returns the sum of the elements of the list.
       sumList([3,4,10]) returns 17
2. makeSentence(L) Take a list of words(strings), and join them in one string with spaces BETWEEN the words.
       makeSentence( ['The','rain','in','Spain','falls','mainly'])   returns 'The rain in Spain falls mainly'  (no space at end)
3. makeListOfSquares(n) returns a list of the first n perfect squares.   
       makeListOfSquares(5) returns [1,4,9,16,25]
4. fib(n) returns the n'th Fibonacci number. This doesn't require lists.
5*. makeFibList(n) takes a non-negative integer n, and returns a list of the first n Fibonacci numbers. (you do NOT need fib for this)