Skip to content
Snippets Groups Projects
Commit c4d8a5b5 authored by Thomas Kennedy's avatar Thomas Kennedy
Browse files

Add README.md to sqrt example

parent 2dcc9b5d
No related branches found
No related tags found
No related merge requests found
# Requirements
* Python 3.7
> This code makes use of the `f"..."` or [f-string
> syntax](https://www.python.org/dev/peps/pep-0498/). This syntax was
> introduced in Python 3.6.
# Sample Execution & Output
If run using
```
./sqrt_demo.py
```
output *simliar* to
```
sqrt(1 + 10^-0 ) = 1.41421356237309514547462185873882845044136047363281
sqrt(1 + 10^-1 ) = 1.04880884817015163079645390098448842763900756835938
sqrt(1 + 10^-2 ) = 1.00498756211208895017250597447855398058891296386719
sqrt(1 + 10^-3 ) = 1.00049987506246096380380095069995149970054626464844
sqrt(1 + 10^-4 ) = 1.00004999875006239662411644530948251485824584960938
sqrt(1 + 10^-5 ) = 1.00000499998750003172176548105198889970779418945312
sqrt(1 + 10^-6 ) = 1.00000049999987505877641069673700258135795593261719
sqrt(1 + 10^-7 ) = 1.00000004999999880794803175376728177070617675781250
sqrt(1 + 10^-8 ) = 1.00000000499999996961264514538925141096115112304688
sqrt(1 + 10^-9 ) = 1.00000000050000004137018549954518675804138183593750
sqrt(1 + 10^-10) = 1.00000000005000000413701854995451867580413818359375
sqrt(1 + 10^-11) = 1.00000000000500000041370185499545186758041381835938
sqrt(1 + 10^-12) = 1.00000000000050004445029117050580680370330810546875
sqrt(1 + 10^-13) = 1.00000000000004996003610813204431906342506408691406
sqrt(1 + 10^-14) = 1.00000000000000488498130835068877786397933959960938
sqrt(1 + 10^-15) = 1.00000000000000044408920985006261616945266723632812
sqrt(1 + 10^-16) = 1.00000000000000000000000000000000000000000000000000
sqrt(1 + 10^-17) = 1.00000000000000000000000000000000000000000000000000
sqrt(1 + 10^-18) = 1.00000000000000000000000000000000000000000000000000
sqrt(1 + 10^-19) = 1.00000000000000000000000000000000000000000000000000
```
will be generated. Note that the output may vary.
......@@ -4,5 +4,6 @@ import math
if __name__ == "__main__":
for d in range(0, 20):
print("{:>50.20f}".format(math.sqrt(1 + 10 ** -d)))
for power in range(0, 20):
result = math.sqrt(1 + 10 ** -power)
print(f" sqrt(1 + 10^-{power:<2d}) = {result:>50.50f}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment