Saint Louis University |
Computer Science 1300/5001
|
Computer Science Department |
All of these problems are for practice. You are freely encouraged to work together and you do not need to submit any of this work for a grade.
Each of the following problems asks you to define a new function with the described behavior. To help you, we've created a framework that will automatically test all of your implementations. Download the file functionLab.py and then place all of your function definitions in the first half of that file. You may run the script to test your work (with the file only testing those functions which you've written).
Write a function f(n) which returns the value $\frac{n(n+1)}{2}$.
Spoiler: my code
Write a function sumOfSquares(n) which returns the sum of the first $n$ squares, $1 + 4 + 9 + \cdots + n^2$.
Spoiler: my code
Write a function with calling signature
Spoiler: my code
Write a function with calling signature
Spoiler: my code
Write a function with calling signature
Spoiler: my code
Write a function with calling signature
Spoiler: my code
Write a function with signature
For example if data were
Spoiler: my code
Write a function with signature
For example if data were
Spoiler: my code
The remove function of the list class only removes the first occurrence of a specified value from the list. Write your own function, removeAll(data, val) that removes all occurrences of the given val from the given list. Note well, you are not to produce a new list, but instead are to modify the given list instance.
Note: there is a relatively easy implementation of this function if relying on other list behaviors, as you can use a while loop that effectively states that while the value occurs on the list, remove the first occurrence of it. It takes more care to implement this without relying so heavily on other list methods.
Spoiler: my code