From fa7bf5f114f812d7e9fe07f5195b7b42c4988f3a Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 12 Sep 2019 07:29:37 -0500 Subject: finish lab --- csci1913/lab1/lab1_strap012.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'csci1913/lab1') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index e04cf82..e7029e1 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -25,17 +25,16 @@ def solve(v, e): def solving(v,q): if left(q)==v: return q - elif type(left(left(q))) is not tuple: + else: if op(left(q))=='+': - return solvingAdd(v, q) + newQ = solvingAdd(v, q) elif op(left(q))=='-': - return solvingSubtract(v, q) + newQ = solvingSubtract(v, q) elif op(left(q))=='*': - return solvingMultiply(v, q) + newQ = solvingMultiply(v, q) elif op(left(q))=='/': - return solvingDivide(v, q) - else: - solving(v,left(q)) + newQ = solvingDivide(v, q) + return solving(v,newQ) def solvingAdd(v,q): if isInside(v, left(left(q))): -- cgit v1.2.3 From fc5325ad8cb87f47a1a9cd80023781204b6569fd Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 12 Sep 2019 07:31:05 -0500 Subject: Add space --- csci1913/lab1/lab1_strap012.py | 1 + 1 file changed, 1 insertion(+) (limited to 'csci1913/lab1') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index e7029e1..329c8c4 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -34,6 +34,7 @@ def solving(v,q): newQ = solvingMultiply(v, q) elif op(left(q))=='/': newQ = solvingDivide(v, q) + return solving(v,newQ) def solvingAdd(v,q): -- cgit v1.2.3 From bc3cc66a4ff6a0780ec47c31847eee5189085782 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 12 Sep 2019 09:45:43 -0500 Subject: Add last if --- csci1913/lab1/lab1_strap012.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'csci1913/lab1') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index 329c8c4..6c6d30b 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -34,6 +34,8 @@ def solving(v,q): newQ = solvingMultiply(v, q) elif op(left(q))=='/': newQ = solvingDivide(v, q) + else: + return 6 return solving(v,newQ) -- cgit v1.2.3 From cc206d788ff868004388f958dbf3bf00a84de0bd Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 12 Sep 2019 10:36:42 -0500 Subject: Change something I guess --- csci1913/lab1/lab1_strap012.py | 1 - 1 file changed, 1 deletion(-) (limited to 'csci1913/lab1') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index 6c6d30b..771734d 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -36,7 +36,6 @@ def solving(v,q): newQ = solvingDivide(v, q) else: return 6 - return solving(v,newQ) def solvingAdd(v,q): -- cgit v1.2.3 From 20fb15d4fefddd12dfc5be30c7175c2bf606a7b8 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Fri, 13 Sep 2019 11:45:06 -0500 Subject: Change something not broken --- csci1913/lab1/lab1_strap012.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'csci1913/lab1') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index 771734d..d69ddc6 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -6,12 +6,13 @@ def right(exp): return exp[2] - def isInside(var, e): if type(e) is tuple: return isInside(var, left(e)) or isInside(var, right(e)) elif type(e) is str: return var==e + else: + return -1 def solve(v, e): if isInside(v, left(e)): @@ -19,49 +20,44 @@ def solve(v, e): elif isInside(v,right(e)): newE=(right(e),op(e),left(e)) return solving(v,newE) + #Solving defined on line 53 else: return None -def solving(v,q): - if left(q)==v: - return q - else: - if op(left(q))=='+': - newQ = solvingAdd(v, q) - elif op(left(q))=='-': - newQ = solvingSubtract(v, q) - elif op(left(q))=='*': - newQ = solvingMultiply(v, q) - elif op(left(q))=='/': - newQ = solvingDivide(v, q) - else: - return 6 - return solving(v,newQ) - +#Four major solving means 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(left(q))) - def solvingSubtract(v,q): if isInside(v, left(left(q))): return left(left(q)), '=', (right(q), '+', right(left(q))) else: return right(left(q)), '=', (left(left(q)), '-', right(q)) - def solvingMultiply(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(left(q))) - def solvingDivide(v,q): if isInside(v, left(left(q))): return left(left(q)), '=', (right(q), '*', right(left(q))) else: return right(left(q)), '=', (left(left(q)), '/', right(q)) +#Dict based off of lecture 13th Sept. 2019 +dispatcher={'+':solvingAdd,'-':solvingSubtract,'*':solvingMultiply,'/':solvingDivide} + +def solving(v,q): + if left(q) is v: + return q + else: + if op(left(q)) in dispatcher: + newQ= dispatcher[op(left(q))](v,q) + else: + return -2 + return solving(v,newQ) # # TESTS. Test the equation solver for CSci 1913 Lab 1. -- cgit v1.2.3 From 11e76f499ef9c8c03884e91d02eea2a88c4acf4d Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Fri, 13 Sep 2019 11:46:56 -0500 Subject: E --- csci1913/lab1/lab1_strap012.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'csci1913/lab1') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py index d69ddc6..48e2ffe 100644 --- a/csci1913/lab1/lab1_strap012.py +++ b/csci1913/lab1/lab1_strap012.py @@ -20,7 +20,7 @@ def solve(v, e): elif isInside(v,right(e)): newE=(right(e),op(e),left(e)) return solving(v,newE) - #Solving defined on line 53 + #Solving defined on line 52 else: return None @@ -56,7 +56,7 @@ def solving(v,q): if op(left(q)) in dispatcher: newQ= dispatcher[op(left(q))](v,q) else: - return -2 + raise ValueError return solving(v,newQ) # -- cgit v1.2.3