## Lab 5, CSC430, Spring 2022

### 1` `Acknowledgments

This lab uses exercises (with permission) from a lab written by Kurt Voelker. Many thanks!

### 2` `Developing Functions

In the exercises below, any instruction to "develop a function" implies the following steps:

Deciding what kind of data the function will accept (in future labs, you will have to make decisions about how the data will be structured),

Writing the first line of the function including the function name and parameter names,

Adding a docstring that indicates the purpose of the function,

Writing test cases for the function using assert, and finally

Writing the body of the function.

### 3` `For loops

Develop the function sum_to_n that accepts a number n and returns the sum of the integers from 1 to n, inclusive.

Develop the function list_sum that accepts a list of numbers nums and returns the sum of the numbers in the list.

Develop the function min_in_list that accepts a list of numbers nums and returns the smallest number in the list.

Develop the function list_fifty_plus that accepts a list of numbers nums and returns True if and only if every element in the list is greater than or equal to 50. It should return False otherwise.

Develop the function many_shorts that accepts a list of strings strs and returns True if there are at least 3 strings with a length less than or equal to 3. It should return False otherwise.

### 4` `List Comprehensions or For loops?

For each of the following, choose a name for the function, write a single nontrivial test case, and specify whether it can be implemented by a list comprehension with a filter clause, or whether it requires a for loop with an accumulator. You do not need to develop a function or write any additional code for any of them.

return the sum of the numbers larger than zero

given a list of strings, return the first one that starts with the letter ’p’

given a list of strings, return the a list containing the ones starting with the letter ’p’.

given a list of lists of numbers, return a list containing the sum of every list with more than 4 elements

### 5` `Plotting

Using plt.plot() and np.linspace(), plot the following function for 100 values in the given range:

f(x) = \frac{(x+5)^2}{4 + 3x^2} \mathrm{for} -3 \leq x \leq 5

Using plt.plot() and np.linspace(), plot the following function for 100 values in the given range:

f(x) = \frac{5\sin(x)}{x + e^{-0.75x}} \mathrm{for} -5 \leq x \leq 10

Using plt.plot() and np.linspace(), plot the following function for 100 values in the given range:

f(x) = \sqrt{|\cos(3x)|} + \sin^2(4x) \textrm{in the domain} -2 \leq x \leq 2

The Gateway Arch in Saint Louis is shaped according to the equation

y = 693 - 68.8\cosh\left(\frac{x}{99.7}\right) \mathrm{ft}

Using plt.plot() and np.linspace(), plot its height for 100 values in the range -300 through 300 feet: