aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-09-13 11:45:06 -0500
committerRossTheRoss <msattr@gmail.com>2019-09-13 11:45:06 -0500
commit20fb15d4fefddd12dfc5be30c7175c2bf606a7b8 (patch)
tree5751f922da09d8c601b4c7bab0af55994d92fadd /csci1913
parentChange something I guess (diff)
downloadhomework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.tar
homework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.tar.gz
homework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.tar.bz2
homework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.tar.lz
homework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.tar.xz
homework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.tar.zst
homework-20fb15d4fefddd12dfc5be30c7175c2bf606a7b8.zip
Change something not broken
Diffstat (limited to 'csci1913')
-rw-r--r--csci1913/lab1/lab1_strap012.py36
1 files changed, 16 insertions, 20 deletions
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.