2014-03-21 + LAB10

posted Mar 21, 2014, 5:48 AM by Samuel Konstantinovich   [ updated Mar 21, 2014, 6:29 AM ]
Goal: To use list methods

DO NOT USE THE BUILTIN COMMANDS FOR THESE PROBLEMS!

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. 
       sumList( [ ] ) returns 0.
    
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) 
makeSentence( [])   returns ''  (empty string)

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.
fib(0) returns 0
fib(1) returns 1
fib(2) returns 1


5*. makeFibList(n) takes a non-negative integer n, and returns a list of the first Fibonacci numbers up to the n'th number. (do NOT use fib for this)
makeFibList(0) -> [0]
makeFibList(5) -> [ 0 1 1 2 3 5]
Comments