Lab 1, CSC430, Spring 2022
1 Starting the Google Colab environment
Google colab is extremely easy to use, because Google probably already knows everything about you including your hat size, your social security number, and the number of children you’re going to have and what their names will be. This is called "vertical integration", and means that you should encounter relatively few roadblocks.
Simply start up a browser, and go to
https://colab.research.google.com/
Use the dialog to create a new notebook, and call it lab1.ipynb
In the first cell, import the pytest library using
import pytest |
... and evaluate that block.
2 Exercises
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.
Naming, function application, and tiny tests:
Give the name my_fruit to the value "banana".
give the name max_fruit_len to the value 256
use assert and the len function to ensure that the length of the my_fruit string is less than max_fruit_len
The beginnings of sequences:
give the name friends to the sequence containing the strings "Mulligatawny", "Zeeberdong", and "Hhavahhrrrr".
use assert to ensure that the second element of the sequence is "Zeeberdong".
Simple functions:
Develop the function dist_from_zero that computes x, y, and z, and computes the euclidean distance from the point (0,0,0) to the point (x,y,z).
Decisions:
Develop the function three_max that accepts three numbers and returns the largest.
Arithmetic:
Develop the function fun1 that accepts x and computes \frac{e^{2x}}{\sqrt{14 + x^2 - x}}.
Develop the function fun2 that accepts x and y and computes \sqrt{xy} - \sqrt{x + y} + \left(\frac{x - y}{x - 2y}\right)^2 - \sqrt{\frac{x}{y}}
Develop the function deriv0 that accepts a function of one argument f, and an input value, and an epsilon value eps, and approximates the derivative using \frac{f(x+\epsilon) - f(x)}{\epsilon}