diff options
author | Matthew Strapp <msattr@gmail.com> | 2019-09-11 15:59:09 -0500 |
---|---|---|
committer | Matthew Strapp <msattr@gmail.com> | 2019-09-11 15:59:09 -0500 |
commit | a2ad4d74e595d476f6cfca926e893082bab27d6e (patch) | |
tree | bb68d3e198a56068dafd4225f5bb303d5e5fa873 | |
parent | ahhh ah (diff) | |
download | homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.tar homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.tar.gz homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.tar.bz2 homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.tar.lz homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.tar.xz homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.tar.zst homework-a2ad4d74e595d476f6cfca926e893082bab27d6e.zip |
More lab
-rw-r--r-- | csci1913/lab1/lab1_strap012.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index 8b8afe4..0e89112 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -17,17 +17,47 @@ def solve(v, e): if isInside(v, left(e)): return solving(v, e) elif isInside(v,right(e)): - newE=(right(e),exp(e),left(e)) + newE=(right(e),op(e),left(e)) return solving(v,newE) else: return None + def solving(v,q): - if type(q) is tuple: + if left(q)==v: + return q + elif type(left(q)): + if op(left(q))=='+': + return solvingAdd(v, q) + elif op(left(q))=='-': + return solvingSubtract(v, q) + elif op(left(q))=='*': + return solvingMultiply(v, q) + elif op(left(q))=='/': + return solvingDivide(v, q) + +def solvingAdd(v,q): + if isInside(v, left(left(q))): + return (left(left(q)), '=', (right(q), '-', right(left(q)))) + else: + return (right(left(q)), '=', (right(q), '-', left(right(q)))) +def solvingSubtract(v,q): + if isInside(v, left(left(q))): + return left(left(q)) + else: + return right(left(q)) +def solvingMultiply(v,q): + if isInside(v, left(left(q))): + return left(left(q)) + else: + return right(left(q)) -def solvingAdd(v,q): - +def solvingDivide(v,q): + if isInside(v, left(left(q))): + return left(left(q)) + else: + return right(left(q)) # # TESTS. Test the equation solver for CSci 1913 Lab 1. |