Created
August 25, 2021 23:06
-
-
Save telliott99/bf740d6ca5fe6ac8ff32e217569a6b8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from fractions import Fraction | |
prog, name, reps, lead = sys.argv[:4] | |
lead, reps = int(lead), int(reps) | |
L = [Fraction(s) for s in sys.argv[4:]] | |
L = L * reps | |
pL = [] | |
def add_invert(n,d): | |
p = 1/d | |
q = n + p | |
pL.append((str(d), str(p), str(n), str(q))) | |
return q | |
def evaluate(L): | |
d = L.pop() | |
while L: | |
n = L.pop() | |
d = add_invert(n,d) | |
return add_invert(lead,d) | |
x = evaluate(L) | |
print(name) | |
for t in pL: | |
print('%10s %10s %4s %10s' % t) | |
print(x) | |
if name.startswith('sqrt'): | |
print('%3.12f' % float(x**2)) | |
else: | |
print('%3.12f' % float(x)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment