Lab 3, CSC430, Spring 2022
1 Acknowledgments
2 Exercises
3 Practice
4 Data Cleaning
5 Systems of Linear Equations
6 Exceptions
8.5

Lab 3, CSC430, Spring 2022

1 Acknowledgments

Portions of this lab are used with permission from assignments written by Kurt Voelker. Many thanks!

2 Exercises

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

  1. 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),

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

  3. Adding a docstring that indicates the purpose of the function,

  4. Writing test cases for the function using assert, and finally

  5. Writing the body of the function.

3 Practice

  1. Develop the function large_squares that accepts a list of numbers my_list and returns a new list that includes the square of each number that is greater than 50.

  2. Develop the function which_in_range that accepts a list of numbers my_list and returns a new list that indicates if each number in the list is in the range [10, 20).

  3. Use numpy functions including zeros, arange, and concatenate to create this array:

    array([[1., 0., 0.],

     

           [2., 0., 0.],

     

           [3., 0., 0.],

     

           [4., 0., 0.]])

4 Data Cleaning

5 Systems of Linear Equations

Use NumPy to solve the following sets of linear equations:

6 Exceptions

  1. Develop the function access that accepts a list of numbers nums and a number idx. Assume this number will be positive. If the number is a valid index in the list (hint: use len), return the item at that index. Otherwise, raise an IndexError with a detailed error message.

  2. Develop the function check_start_abc that accepts a string. If the string starts with "a", "b", or "c" , return the string. Otherwise raise a ValueError with a detailed error message.

  3. Develop the function divide that accepts two numbers. If the second number is zero, raise a ZeroDivisionError with a detailed error message. Otherwise, return the result of dividing the first by the second.