... | ... | @@ -2516,7 +2516,66 @@ Date: Mon Mar 2 15:17:38 2020 -0500 |
|
|
|
|
|
#### Adding Some Python Code
|
|
|
|
|
|
Now we are ready to start adding some actual code. Both `.gitignore`
|
|
|
and `README.md` files should always be created proactively during initial repo
|
|
|
creation. These files must never be an after thought.
|
|
|
|
|
|
1. Create new Python file named `newtons_method.py`.
|
|
|
2. Copy the example code from the `newtons_method_1.py` listing from
|
|
|
[here](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
into the file.
|
|
|
3. Run `git add newtons_method.py`
|
|
|
4. Run `git commit -m "Add initial draft of newton's method code"`
|
|
|
5. Copy the example code from the `newtons_method_2.py` listing from
|
|
|
[here](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
into `newtons_method.py`, replacing the previous contents.
|
|
|
6. Run `git add .`
|
|
|
7. Run `git commit -m "Tweak code to use tuples and tuple unpacking"`
|
|
|
8. Copy the example code from the `newtons_method_3.py` listing from
|
|
|
[here](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
into `newtons_method.py`, replacing the previous contents.
|
|
|
8. Run `git add .`
|
|
|
8. Run `git commit -m "Annotate code with Python type hints"`
|
|
|
8. Copy the example code from the `newtons_method_4.py` listing from
|
|
|
[here](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
into `newtons_method.py`, replacing the previous contents.
|
|
|
8. Run `git add .`
|
|
|
8. Run `git commit -m "Add missing pydoc function docstrings"`
|
|
|
8. Copy the example code from the `newtons_method_5.py` listing from
|
|
|
[here](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
into `newtons_method.py`, replacing the previous contents.
|
|
|
8. Run `git add .`
|
|
|
8. Run `git commit -m "Clean up unused imports & add main function docstring"`
|
|
|
8. Copy the example code from the `newtons_method_6.py` listing from
|
|
|
[here](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
into `newtons_method.py`, replacing the previous contents.
|
|
|
8. Run `git add .`
|
|
|
8. Run `git commit -m "Modify code to use Python's Decimal type instead of float"`
|
|
|
|
|
|
Let us make one final edit. Let us fix this missing output listing in `README.md`
|
|
|
|
|
|
1. Open `README.md`
|
|
|
2. Add the following content to the end of the file.
|
|
|
|
|
|
````
|
|
|
|
|
|
If run using
|
|
|
|
|
|
```
|
|
|
python newtons_method.py 2
|
|
|
```
|
|
|
|
|
|
output simliar to
|
|
|
|
|
|
```
|
|
|
x = 1.0000000469590518 | f(x) = 9.391810573688986e-08 | 5 iterations
|
|
|
```
|
|
|
|
|
|
should be generated.
|
|
|
````
|
|
|
|
|
|
8. Run `git add .`
|
|
|
8. Run `git commit -m "Add missing sample output to README"`
|
|
|
|
|
|
---
|
|
|
|
... | ... | |