From 41f37c5364416d2ff3deb0bbf68a82f1e1b9c9de Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Wed, 18 Sep 2019 18:57:32 -0500 Subject: Less broken now --- csci1913/lab1/lab2_strap012.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 34fbe6a..7480447 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -1,11 +1,16 @@ class Zillion: def __init__(self,digits): self.digits = digits - if (1==1): - try: - int(digits) - except ValueError: - raise RuntimeError + self.__x=0 + if digits is not '': + for __x in range (0,len(digits)): + if digits[__x] is (not ' ') or (not ','): + try: + int(digits[__x]) + except ValueError: + raise RuntimeError + else: + raise RuntimeError def increment(self): return int(self.digits)+1 def isZero(self): -- cgit v1.2.3 From 8cdbe123f45eff58627baa1bd277518656561076 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 19 Sep 2019 19:09:12 -0500 Subject: ch-ch-ch-ch-changes --- csci1913/lab1/lab2_strap012.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 7480447..50db0ea 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -4,11 +4,10 @@ class Zillion: self.__x=0 if digits is not '': for __x in range (0,len(digits)): - if digits[__x] is (not ' ') or (not ','): - try: - int(digits[__x]) - except ValueError: - raise RuntimeError + try: + int(digits[__x]) + except ValueError: + raise RuntimeError else: raise RuntimeError def increment(self): -- cgit v1.2.3 From a1c705c5b3024984740138b463553f84edfa0b0b Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 23 Sep 2019 13:03:05 -0500 Subject: Final stretches of a bad mess --- csci1913/lab1/lab2_strap012.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 50db0ea..1a9b601 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -2,23 +2,37 @@ class Zillion: def __init__(self,digits): self.digits = digits self.__x=0 - if digits is not '': - for __x in range (0,len(digits)): - try: - int(digits[__x]) - except ValueError: - raise RuntimeError - else: + self.List = [] + self.toList() + def toList(self): + badBoolean=False + if len(self.digits) == 0: + raise RuntimeError #Cannot make a list of nothing + for n in range (0,len(self.digits)): + if self.digits[n] is not ',': + if self.digits[n] is not ' ': + try: + self.List+=[int(self.digits[n])] + badBoolean=True + except ValueError: + raise RuntimeError + if badBoolean is False: raise RuntimeError + else: + return self.List def increment(self): - return int(self.digits)+1 + return None def isZero(self): - for n in range (0,len(self.digits)): - if str(self.digits)[n] is not '0': + for p in range (0,len(self.List)-1): + if self.List[p] is not 0 or not '0': return False return True def toString(self): - return str(self.digits) + string='' + for q in range (0,len(self.List)): + string+=str(self.List[q]) + return string + -- cgit v1.2.3 From 02fd0396cc895c1e644e8cb5e1dc097a2bfc8870 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 23 Sep 2019 13:09:24 -0500 Subject: E --- csci1913/lab1/lab2_strap012.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 1a9b601..1ff1a28 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -21,7 +21,10 @@ class Zillion: else: return self.List def increment(self): - return None + newList=self.List + newList[len(self.List)-1] += 1 + if newList[len(self.List)-1]>=10: + def isZero(self): for p in range (0,len(self.List)-1): if self.List[p] is not 0 or not '0': @@ -35,7 +38,6 @@ class Zillion: - # # TESTS. Test the class Zillion for CSci 1913 Lab 2. # -- cgit v1.2.3 From 6c38e0ac3622e452e953a1f1eda62fdf62b7ce2b Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 23 Sep 2019 14:47:27 -0500 Subject: Fix an oopsie --- csci1913/lab1/lab2_strap012.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 1ff1a28..7fc6ff3 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -24,7 +24,7 @@ class Zillion: newList=self.List newList[len(self.List)-1] += 1 if newList[len(self.List)-1]>=10: - + return None def isZero(self): for p in range (0,len(self.List)-1): if self.List[p] is not 0 or not '0': -- cgit v1.2.3 From 4ca3e9f6f2fdabbc324b5914a8f1b7db7a0ed83a Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 23 Sep 2019 18:38:47 -0500 Subject: Finish lab --- csci1913/lab1/lab2_strap012.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 7fc6ff3..0aa368b 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -21,10 +21,13 @@ class Zillion: else: return self.List def increment(self): - newList=self.List + length = len(self.List) - 1 + newList = self.List newList[len(self.List)-1] += 1 - if newList[len(self.List)-1]>=10: - return None + if newList[length]>=10: + for n in range (0,length): + newList[length-n]=0 + newList[length-n-1]+=1 def isZero(self): for p in range (0,len(self.List)-1): if self.List[p] is not 0 or not '0': -- cgit v1.2.3 From 6a3afcfdd556d332d295aed38bec83a9c134cf63 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 23 Sep 2019 18:40:11 -0500 Subject: Format lab gooder --- csci1913/lab1/lab2_strap012.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 0aa368b..8c5798e 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -1,25 +1,27 @@ class Zillion: def __init__(self,digits): self.digits = digits - self.__x=0 self.List = [] self.toList() + def toList(self): badBoolean=False - if len(self.digits) == 0: - raise RuntimeError #Cannot make a list of nothing + if len(self.digits) == 0 : + raise RuntimeError #Cannot make a list of nothing for n in range (0,len(self.digits)): if self.digits[n] is not ',': if self.digits[n] is not ' ': try: self.List+=[int(self.digits[n])] badBoolean=True - except ValueError: + except ValueError: #Non-comma character in string raise RuntimeError - if badBoolean is False: + if badBoolean is False: #No numbers in string raise RuntimeError else: return self.List + + def increment(self): length = len(self.List) - 1 newList = self.List @@ -28,11 +30,13 @@ class Zillion: for n in range (0,length): newList[length-n]=0 newList[length-n-1]+=1 + def isZero(self): for p in range (0,len(self.List)-1): if self.List[p] is not 0 or not '0': return False return True + def toString(self): string='' for q in range (0,len(self.List)): -- cgit v1.2.3 From e1a1583a32ee596ebd152d795345f6e0dbe8906b Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 23 Sep 2019 18:42:14 -0500 Subject: C O M M E N T S --- csci1913/lab1/lab2_strap012.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'csci1913') diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py index 8c5798e..4e154f7 100644 --- a/csci1913/lab1/lab2_strap012.py +++ b/csci1913/lab1/lab2_strap012.py @@ -5,7 +5,7 @@ class Zillion: self.toList() def toList(self): - badBoolean=False + badBoolean=False #Kludge if len(self.digits) == 0 : raise RuntimeError #Cannot make a list of nothing for n in range (0,len(self.digits)): @@ -26,21 +26,21 @@ class Zillion: length = len(self.List) - 1 newList = self.List newList[len(self.List)-1] += 1 - if newList[length]>=10: + if newList[length]>=10: #Loop to increment all 10s to 0s with carry for n in range (0,length): newList[length-n]=0 newList[length-n-1]+=1 def isZero(self): for p in range (0,len(self.List)-1): - if self.List[p] is not 0 or not '0': + if self.List[p] is not 0: return False return True - + def toString(self): string='' for q in range (0,len(self.List)): - string+=str(self.List[q]) + string+=str(self.List[q]) #Make string by concatenation return string -- cgit v1.2.3 From 2e184d746d63bb944c7a717991d86cadcb830dcf Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 24 Sep 2019 09:49:14 -0500 Subject: Rearrange things --- csci1913/lab1/lab1_strap012.py | 115 ---------------------------------- csci1913/lab1/lab2_strap012.py | 137 ----------------------------------------- csci1913/lab1_strap012.py | 115 ++++++++++++++++++++++++++++++++++ csci1913/lab2_strap012.py | 137 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 252 insertions(+), 252 deletions(-) delete mode 100644 csci1913/lab1/lab1_strap012.py delete mode 100644 csci1913/lab1/lab2_strap012.py create mode 100644 csci1913/lab1_strap012.py create mode 100644 csci1913/lab2_strap012.py (limited to 'csci1913') diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/lab1/lab1_strap012.py deleted file mode 100644 index 396fda9..0000000 --- a/csci1913/lab1/lab1_strap012.py +++ /dev/null @@ -1,115 +0,0 @@ -#Matthew Strapp -#5449340 -#Lab 1 - -def left(exp): - return exp[0] -def op(exp): - return exp[1] -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)): - return solving(v, e) - elif isInside(v,right(e)): - newE=(right(e),op(e),left(e)) - return solving(v,newE) - #Solving defined on line 52 - else: - return None - -#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: - raise ValueError - return solving(v,newQ) - -# -# TESTS. Test the equation solver for CSci 1913 Lab 1. -# -# James Moen -# 10 Sep 18 -# -# Every test is followed by a comment which shows what must be printed if your -# code works correctly. It also shows how many points the test is worth, for a -# total of 35 possible points. -# - -print(isInside('x', 'x')) # True 1 point -print(isInside('x', 'y')) # False 1 point -print(isInside('x', ('x', '+', 'y'))) # True 2 points -print(isInside('x', ('a', '+', 'b'))) # False 2 points -print(isInside('+', ('a', '+', 'b'))) # False 2 points -print(isInside('x', (('m', '*', 'x'), '+', 'b'))) # True 2 points - -print(solve('x', (('a', '+', 'x'), '=', 'c'))) -# ('x', '=', ('c', '-', 'a')) 2 points - -print(solve('x', (('x', '+', 'b'), '=', 'c'))) -# ('x', '=', ('c', '-', 'b')) 2 points - -print(solve('x', (('a', '-', 'x'), '=', 'c'))) -# ('x', '=', ('a', '-', 'c')) 2 points - -print(solve('x', (('x', '-', 'b'), '=', 'c'))) -# ('x', '=', ('c', '+', 'b')) 2 points - -print(solve('x', (('a', '*', 'x'), '=', 'c'))) -# ('x', '=', ('c', '/', 'a')) 2 points - -print(solve('x', (('x', '*', 'b'), '=', 'c'))) -# ('x', '=', ('c', '/', 'b')) 2 points - -print(solve('x', (('a', '/', 'x'), '=', 'c'))) -# ('x', '=', ('a', '/', 'c')) 2 points - -print(solve('x', (('x', '/', 'b'), '=', 'c'))) -# ('x', '=', ('c', '*', 'b')) 2 points - -print(solve('y', ('y', '=', (('m', '*', 'x'), '+', 'b')))) -# ('y', '=', (('m', '*', 'x'), '+', 'b')) 2 points - -print(solve('x', ('y', '=', (('m', '*', 'x'), '+', 'b')))) -# ('x', '=', (('y', '-', 'b'), '/', 'm')) 2 points - -print(solve('a', (('b', '+', 'c'), '=', ('d', '*', (('a', '/', 'e'), '-', 'f'))))) -# ('a', '=', (((('b', '+', 'c'), '/', 'd'), '+', 'f'), '*', 'e')) 5 points \ No newline at end of file diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py deleted file mode 100644 index 4e154f7..0000000 --- a/csci1913/lab1/lab2_strap012.py +++ /dev/null @@ -1,137 +0,0 @@ -class Zillion: - def __init__(self,digits): - self.digits = digits - self.List = [] - self.toList() - - def toList(self): - badBoolean=False #Kludge - if len(self.digits) == 0 : - raise RuntimeError #Cannot make a list of nothing - for n in range (0,len(self.digits)): - if self.digits[n] is not ',': - if self.digits[n] is not ' ': - try: - self.List+=[int(self.digits[n])] - badBoolean=True - except ValueError: #Non-comma character in string - raise RuntimeError - if badBoolean is False: #No numbers in string - raise RuntimeError - else: - return self.List - - - def increment(self): - length = len(self.List) - 1 - newList = self.List - newList[len(self.List)-1] += 1 - if newList[length]>=10: #Loop to increment all 10s to 0s with carry - for n in range (0,length): - newList[length-n]=0 - newList[length-n-1]+=1 - - def isZero(self): - for p in range (0,len(self.List)-1): - if self.List[p] is not 0: - return False - return True - - def toString(self): - string='' - for q in range (0,len(self.List)): - string+=str(self.List[q]) #Make string by concatenation - return string - - - -# -# TESTS. Test the class Zillion for CSci 1913 Lab 2. -# -# James Moen -# 18 Sep 17 -# -# Every test is followed by a comment which shows what must be printed if your -# code works correctly. It also shows how many points the test is worth. -# - -try: - z = Zillion('') -except RuntimeError: - print('Empty string') - -# It must print 'Empty string' without apostrophes. 2 points. - -try: - z = Zillion(' , ') -except RuntimeError: - print('No digits in the string') - -# It must print 'No digits in the string' without apostrophes. 2 points. - -try: - z = Zillion('1+0') -except RuntimeError: - print('Non-digit in the string') - -# It must print 'Non-digit in the string' without apostrophes. 2 points. - -try: - z = Zillion('0') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print True. 2 points. - -try: - z = Zillion('000000000') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print True. 2 points. - -try: - z = Zillion('000 000 000') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print True. 2 points. - -try: - z = Zillion('997') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print False. 2 points. - -print(z.toString()) # It must print 997. 2 points. - -z.increment() - -print(z.toString()) # It must print 998. 2 points. - -z.increment() - -print(z.toString()) # It must print 999. 2 points. - -z.increment() - -print(z.toString()) # It must print 1000. 2 points. - -try: - z = Zillion('0 9,9 9') -except: - print('This must not be printed') - -# It must print nothing. 3 points. - -z.increment() -print(z.toString()) # It must print 1000. 2 points. diff --git a/csci1913/lab1_strap012.py b/csci1913/lab1_strap012.py new file mode 100644 index 0000000..396fda9 --- /dev/null +++ b/csci1913/lab1_strap012.py @@ -0,0 +1,115 @@ +#Matthew Strapp +#5449340 +#Lab 1 + +def left(exp): + return exp[0] +def op(exp): + return exp[1] +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)): + return solving(v, e) + elif isInside(v,right(e)): + newE=(right(e),op(e),left(e)) + return solving(v,newE) + #Solving defined on line 52 + else: + return None + +#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: + raise ValueError + return solving(v,newQ) + +# +# TESTS. Test the equation solver for CSci 1913 Lab 1. +# +# James Moen +# 10 Sep 18 +# +# Every test is followed by a comment which shows what must be printed if your +# code works correctly. It also shows how many points the test is worth, for a +# total of 35 possible points. +# + +print(isInside('x', 'x')) # True 1 point +print(isInside('x', 'y')) # False 1 point +print(isInside('x', ('x', '+', 'y'))) # True 2 points +print(isInside('x', ('a', '+', 'b'))) # False 2 points +print(isInside('+', ('a', '+', 'b'))) # False 2 points +print(isInside('x', (('m', '*', 'x'), '+', 'b'))) # True 2 points + +print(solve('x', (('a', '+', 'x'), '=', 'c'))) +# ('x', '=', ('c', '-', 'a')) 2 points + +print(solve('x', (('x', '+', 'b'), '=', 'c'))) +# ('x', '=', ('c', '-', 'b')) 2 points + +print(solve('x', (('a', '-', 'x'), '=', 'c'))) +# ('x', '=', ('a', '-', 'c')) 2 points + +print(solve('x', (('x', '-', 'b'), '=', 'c'))) +# ('x', '=', ('c', '+', 'b')) 2 points + +print(solve('x', (('a', '*', 'x'), '=', 'c'))) +# ('x', '=', ('c', '/', 'a')) 2 points + +print(solve('x', (('x', '*', 'b'), '=', 'c'))) +# ('x', '=', ('c', '/', 'b')) 2 points + +print(solve('x', (('a', '/', 'x'), '=', 'c'))) +# ('x', '=', ('a', '/', 'c')) 2 points + +print(solve('x', (('x', '/', 'b'), '=', 'c'))) +# ('x', '=', ('c', '*', 'b')) 2 points + +print(solve('y', ('y', '=', (('m', '*', 'x'), '+', 'b')))) +# ('y', '=', (('m', '*', 'x'), '+', 'b')) 2 points + +print(solve('x', ('y', '=', (('m', '*', 'x'), '+', 'b')))) +# ('x', '=', (('y', '-', 'b'), '/', 'm')) 2 points + +print(solve('a', (('b', '+', 'c'), '=', ('d', '*', (('a', '/', 'e'), '-', 'f'))))) +# ('a', '=', (((('b', '+', 'c'), '/', 'd'), '+', 'f'), '*', 'e')) 5 points \ No newline at end of file diff --git a/csci1913/lab2_strap012.py b/csci1913/lab2_strap012.py new file mode 100644 index 0000000..4e154f7 --- /dev/null +++ b/csci1913/lab2_strap012.py @@ -0,0 +1,137 @@ +class Zillion: + def __init__(self,digits): + self.digits = digits + self.List = [] + self.toList() + + def toList(self): + badBoolean=False #Kludge + if len(self.digits) == 0 : + raise RuntimeError #Cannot make a list of nothing + for n in range (0,len(self.digits)): + if self.digits[n] is not ',': + if self.digits[n] is not ' ': + try: + self.List+=[int(self.digits[n])] + badBoolean=True + except ValueError: #Non-comma character in string + raise RuntimeError + if badBoolean is False: #No numbers in string + raise RuntimeError + else: + return self.List + + + def increment(self): + length = len(self.List) - 1 + newList = self.List + newList[len(self.List)-1] += 1 + if newList[length]>=10: #Loop to increment all 10s to 0s with carry + for n in range (0,length): + newList[length-n]=0 + newList[length-n-1]+=1 + + def isZero(self): + for p in range (0,len(self.List)-1): + if self.List[p] is not 0: + return False + return True + + def toString(self): + string='' + for q in range (0,len(self.List)): + string+=str(self.List[q]) #Make string by concatenation + return string + + + +# +# TESTS. Test the class Zillion for CSci 1913 Lab 2. +# +# James Moen +# 18 Sep 17 +# +# Every test is followed by a comment which shows what must be printed if your +# code works correctly. It also shows how many points the test is worth. +# + +try: + z = Zillion('') +except RuntimeError: + print('Empty string') + +# It must print 'Empty string' without apostrophes. 2 points. + +try: + z = Zillion(' , ') +except RuntimeError: + print('No digits in the string') + +# It must print 'No digits in the string' without apostrophes. 2 points. + +try: + z = Zillion('1+0') +except RuntimeError: + print('Non-digit in the string') + +# It must print 'Non-digit in the string' without apostrophes. 2 points. + +try: + z = Zillion('0') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print True. 2 points. + +try: + z = Zillion('000000000') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print True. 2 points. + +try: + z = Zillion('000 000 000') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print True. 2 points. + +try: + z = Zillion('997') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print False. 2 points. + +print(z.toString()) # It must print 997. 2 points. + +z.increment() + +print(z.toString()) # It must print 998. 2 points. + +z.increment() + +print(z.toString()) # It must print 999. 2 points. + +z.increment() + +print(z.toString()) # It must print 1000. 2 points. + +try: + z = Zillion('0 9,9 9') +except: + print('This must not be printed') + +# It must print nothing. 3 points. + +z.increment() +print(z.toString()) # It must print 1000. 2 points. -- cgit v1.2.3 From a92b8f2407490bb48ccec5e067a80dd02edd578b Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 24 Sep 2019 09:52:05 -0500 Subject: Format things gooder --- .vscode/launch.json | 111 ++++--------------------------- csci1913/Python/lab1_strap012.py | 115 ++++++++++++++++++++++++++++++++ csci1913/Python/lab2_strap012.py | 137 +++++++++++++++++++++++++++++++++++++++ csci1913/lab1_strap012.py | 115 -------------------------------- csci1913/lab2_strap012.py | 137 --------------------------------------- 5 files changed, 265 insertions(+), 350 deletions(-) create mode 100644 csci1913/Python/lab1_strap012.py create mode 100644 csci1913/Python/lab2_strap012.py delete mode 100644 csci1913/lab1_strap012.py delete mode 100644 csci1913/lab2_strap012.py (limited to 'csci1913') diff --git a/.vscode/launch.json b/.vscode/launch.json index 20c3726..42a2cbe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,19 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Python", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + }, + { + "type": "java", + "name": "Java", + "request": "launch", + "mainClass": "" + }, { "name": "(gdb) Launch", "type": "cppdbg", @@ -23,103 +36,5 @@ } ] }, - - { - "name": "Python", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - }, - { - "type": "java", - "name": "Java", - "request": "launch", - "mainClass": "" - }, - // { - // "type": "cortex-debug", - // "request": "attach", - // "name": "Particle Debugger (photon, p1, electron)", - // "servertype": "openocd", - // "interface": "swd", - // "device": "STM32F205RG", - // "cwd": "${workspaceRoot}", - // "executable": "${command:particle.getDebuggerExecutable}", - // "preLaunchTask": "Particle: Flash application for debug (local)", - // "armToolchainPath": "${command:particle.getDebuggerCompilerDir}", - // "svdFile": "${command:particle.getDebuggerSVDFile}", - // "searchDir": [ - // "${command:particle.getDebuggerSearchDir}" - // ], - // "configFiles": [ - // "interface/cmsis-dap.cfg", - // "target/stm32f2x.cfg" - // ], - // "postAttachCommands": [ - // "monitor reset halt" - // ], - // "windows": { - // "configFiles": [ - // "interface\\cmsis-dap.cfg", - // "target\\stm32f2x.cfg" - // ] - // } - // }, - // { - // "type": "cortex-debug", - // "request": "attach", - // "name": "Particle Debugger (argon, boron, xenon)", - // "servertype": "openocd", - // "interface": "swd", - // "device": "nRF52840_xxAA", - // "cwd": "${workspaceRoot}", - // "executable": "${command:particle.getDebuggerExecutable}", - // "preLaunchTask": "Particle: Flash application for debug (local)", - // "armToolchainPath": "${command:particle.getDebuggerCompilerDir}", - // "svdFile": "${command:particle.getDebuggerSVDFile}", - // "searchDir": [ - // "${command:particle.getDebuggerSearchDir}" - // ], - // "configFiles": [ - // "interface/cmsis-dap.cfg", - // "target/nrf52-particle.cfg" - // ], - // "windows": { - // "configFiles": [ - // "interface\\cmsis-dap.cfg", - // "target\\nrf52-particle.cfg" - // ] - // } - // }, - // { - // "type": "cortex-debug", - // "request": "attach", - // "name": "Particle Programmer Shield v1.0 (photon, p1, electron)", - // "servertype": "openocd", - // "interface": "swd", - // "device": "STM32F205RG", - // "cwd": "${workspaceRoot}", - // "executable": "${command:particle.getDebuggerExecutable}", - // "preLaunchTask": "Particle: Flash application for debug (local)", - // "armToolchainPath": "${command:particle.getDebuggerCompilerDir}", - // "svdFile": "${command:particle.getDebuggerSVDFile}", - // "searchDir": [ - // "${command:particle.getDebuggerSearchDir}" - // ], - // "configFiles": [ - // "interface/particle-ftdi.cfg", - // "target/stm32f2x.cfg" - // ], - // "postAttachCommands": [ - // "monitor reset halt" - // ], - // "windows": { - // "configFiles": [ - // "interface\\particle-ftdi.cfg", - // "target\\stm32f2x.cfg" - // ] - // } - // } ] } \ No newline at end of file diff --git a/csci1913/Python/lab1_strap012.py b/csci1913/Python/lab1_strap012.py new file mode 100644 index 0000000..396fda9 --- /dev/null +++ b/csci1913/Python/lab1_strap012.py @@ -0,0 +1,115 @@ +#Matthew Strapp +#5449340 +#Lab 1 + +def left(exp): + return exp[0] +def op(exp): + return exp[1] +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)): + return solving(v, e) + elif isInside(v,right(e)): + newE=(right(e),op(e),left(e)) + return solving(v,newE) + #Solving defined on line 52 + else: + return None + +#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: + raise ValueError + return solving(v,newQ) + +# +# TESTS. Test the equation solver for CSci 1913 Lab 1. +# +# James Moen +# 10 Sep 18 +# +# Every test is followed by a comment which shows what must be printed if your +# code works correctly. It also shows how many points the test is worth, for a +# total of 35 possible points. +# + +print(isInside('x', 'x')) # True 1 point +print(isInside('x', 'y')) # False 1 point +print(isInside('x', ('x', '+', 'y'))) # True 2 points +print(isInside('x', ('a', '+', 'b'))) # False 2 points +print(isInside('+', ('a', '+', 'b'))) # False 2 points +print(isInside('x', (('m', '*', 'x'), '+', 'b'))) # True 2 points + +print(solve('x', (('a', '+', 'x'), '=', 'c'))) +# ('x', '=', ('c', '-', 'a')) 2 points + +print(solve('x', (('x', '+', 'b'), '=', 'c'))) +# ('x', '=', ('c', '-', 'b')) 2 points + +print(solve('x', (('a', '-', 'x'), '=', 'c'))) +# ('x', '=', ('a', '-', 'c')) 2 points + +print(solve('x', (('x', '-', 'b'), '=', 'c'))) +# ('x', '=', ('c', '+', 'b')) 2 points + +print(solve('x', (('a', '*', 'x'), '=', 'c'))) +# ('x', '=', ('c', '/', 'a')) 2 points + +print(solve('x', (('x', '*', 'b'), '=', 'c'))) +# ('x', '=', ('c', '/', 'b')) 2 points + +print(solve('x', (('a', '/', 'x'), '=', 'c'))) +# ('x', '=', ('a', '/', 'c')) 2 points + +print(solve('x', (('x', '/', 'b'), '=', 'c'))) +# ('x', '=', ('c', '*', 'b')) 2 points + +print(solve('y', ('y', '=', (('m', '*', 'x'), '+', 'b')))) +# ('y', '=', (('m', '*', 'x'), '+', 'b')) 2 points + +print(solve('x', ('y', '=', (('m', '*', 'x'), '+', 'b')))) +# ('x', '=', (('y', '-', 'b'), '/', 'm')) 2 points + +print(solve('a', (('b', '+', 'c'), '=', ('d', '*', (('a', '/', 'e'), '-', 'f'))))) +# ('a', '=', (((('b', '+', 'c'), '/', 'd'), '+', 'f'), '*', 'e')) 5 points \ No newline at end of file diff --git a/csci1913/Python/lab2_strap012.py b/csci1913/Python/lab2_strap012.py new file mode 100644 index 0000000..4e154f7 --- /dev/null +++ b/csci1913/Python/lab2_strap012.py @@ -0,0 +1,137 @@ +class Zillion: + def __init__(self,digits): + self.digits = digits + self.List = [] + self.toList() + + def toList(self): + badBoolean=False #Kludge + if len(self.digits) == 0 : + raise RuntimeError #Cannot make a list of nothing + for n in range (0,len(self.digits)): + if self.digits[n] is not ',': + if self.digits[n] is not ' ': + try: + self.List+=[int(self.digits[n])] + badBoolean=True + except ValueError: #Non-comma character in string + raise RuntimeError + if badBoolean is False: #No numbers in string + raise RuntimeError + else: + return self.List + + + def increment(self): + length = len(self.List) - 1 + newList = self.List + newList[len(self.List)-1] += 1 + if newList[length]>=10: #Loop to increment all 10s to 0s with carry + for n in range (0,length): + newList[length-n]=0 + newList[length-n-1]+=1 + + def isZero(self): + for p in range (0,len(self.List)-1): + if self.List[p] is not 0: + return False + return True + + def toString(self): + string='' + for q in range (0,len(self.List)): + string+=str(self.List[q]) #Make string by concatenation + return string + + + +# +# TESTS. Test the class Zillion for CSci 1913 Lab 2. +# +# James Moen +# 18 Sep 17 +# +# Every test is followed by a comment which shows what must be printed if your +# code works correctly. It also shows how many points the test is worth. +# + +try: + z = Zillion('') +except RuntimeError: + print('Empty string') + +# It must print 'Empty string' without apostrophes. 2 points. + +try: + z = Zillion(' , ') +except RuntimeError: + print('No digits in the string') + +# It must print 'No digits in the string' without apostrophes. 2 points. + +try: + z = Zillion('1+0') +except RuntimeError: + print('Non-digit in the string') + +# It must print 'Non-digit in the string' without apostrophes. 2 points. + +try: + z = Zillion('0') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print True. 2 points. + +try: + z = Zillion('000000000') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print True. 2 points. + +try: + z = Zillion('000 000 000') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print True. 2 points. + +try: + z = Zillion('997') +except RuntimeError: + print('This must not be printed') + +# It must print nothing. 2 points. + +print(z.isZero()) # It must print False. 2 points. + +print(z.toString()) # It must print 997. 2 points. + +z.increment() + +print(z.toString()) # It must print 998. 2 points. + +z.increment() + +print(z.toString()) # It must print 999. 2 points. + +z.increment() + +print(z.toString()) # It must print 1000. 2 points. + +try: + z = Zillion('0 9,9 9') +except: + print('This must not be printed') + +# It must print nothing. 3 points. + +z.increment() +print(z.toString()) # It must print 1000. 2 points. diff --git a/csci1913/lab1_strap012.py b/csci1913/lab1_strap012.py deleted file mode 100644 index 396fda9..0000000 --- a/csci1913/lab1_strap012.py +++ /dev/null @@ -1,115 +0,0 @@ -#Matthew Strapp -#5449340 -#Lab 1 - -def left(exp): - return exp[0] -def op(exp): - return exp[1] -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)): - return solving(v, e) - elif isInside(v,right(e)): - newE=(right(e),op(e),left(e)) - return solving(v,newE) - #Solving defined on line 52 - else: - return None - -#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: - raise ValueError - return solving(v,newQ) - -# -# TESTS. Test the equation solver for CSci 1913 Lab 1. -# -# James Moen -# 10 Sep 18 -# -# Every test is followed by a comment which shows what must be printed if your -# code works correctly. It also shows how many points the test is worth, for a -# total of 35 possible points. -# - -print(isInside('x', 'x')) # True 1 point -print(isInside('x', 'y')) # False 1 point -print(isInside('x', ('x', '+', 'y'))) # True 2 points -print(isInside('x', ('a', '+', 'b'))) # False 2 points -print(isInside('+', ('a', '+', 'b'))) # False 2 points -print(isInside('x', (('m', '*', 'x'), '+', 'b'))) # True 2 points - -print(solve('x', (('a', '+', 'x'), '=', 'c'))) -# ('x', '=', ('c', '-', 'a')) 2 points - -print(solve('x', (('x', '+', 'b'), '=', 'c'))) -# ('x', '=', ('c', '-', 'b')) 2 points - -print(solve('x', (('a', '-', 'x'), '=', 'c'))) -# ('x', '=', ('a', '-', 'c')) 2 points - -print(solve('x', (('x', '-', 'b'), '=', 'c'))) -# ('x', '=', ('c', '+', 'b')) 2 points - -print(solve('x', (('a', '*', 'x'), '=', 'c'))) -# ('x', '=', ('c', '/', 'a')) 2 points - -print(solve('x', (('x', '*', 'b'), '=', 'c'))) -# ('x', '=', ('c', '/', 'b')) 2 points - -print(solve('x', (('a', '/', 'x'), '=', 'c'))) -# ('x', '=', ('a', '/', 'c')) 2 points - -print(solve('x', (('x', '/', 'b'), '=', 'c'))) -# ('x', '=', ('c', '*', 'b')) 2 points - -print(solve('y', ('y', '=', (('m', '*', 'x'), '+', 'b')))) -# ('y', '=', (('m', '*', 'x'), '+', 'b')) 2 points - -print(solve('x', ('y', '=', (('m', '*', 'x'), '+', 'b')))) -# ('x', '=', (('y', '-', 'b'), '/', 'm')) 2 points - -print(solve('a', (('b', '+', 'c'), '=', ('d', '*', (('a', '/', 'e'), '-', 'f'))))) -# ('a', '=', (((('b', '+', 'c'), '/', 'd'), '+', 'f'), '*', 'e')) 5 points \ No newline at end of file diff --git a/csci1913/lab2_strap012.py b/csci1913/lab2_strap012.py deleted file mode 100644 index 4e154f7..0000000 --- a/csci1913/lab2_strap012.py +++ /dev/null @@ -1,137 +0,0 @@ -class Zillion: - def __init__(self,digits): - self.digits = digits - self.List = [] - self.toList() - - def toList(self): - badBoolean=False #Kludge - if len(self.digits) == 0 : - raise RuntimeError #Cannot make a list of nothing - for n in range (0,len(self.digits)): - if self.digits[n] is not ',': - if self.digits[n] is not ' ': - try: - self.List+=[int(self.digits[n])] - badBoolean=True - except ValueError: #Non-comma character in string - raise RuntimeError - if badBoolean is False: #No numbers in string - raise RuntimeError - else: - return self.List - - - def increment(self): - length = len(self.List) - 1 - newList = self.List - newList[len(self.List)-1] += 1 - if newList[length]>=10: #Loop to increment all 10s to 0s with carry - for n in range (0,length): - newList[length-n]=0 - newList[length-n-1]+=1 - - def isZero(self): - for p in range (0,len(self.List)-1): - if self.List[p] is not 0: - return False - return True - - def toString(self): - string='' - for q in range (0,len(self.List)): - string+=str(self.List[q]) #Make string by concatenation - return string - - - -# -# TESTS. Test the class Zillion for CSci 1913 Lab 2. -# -# James Moen -# 18 Sep 17 -# -# Every test is followed by a comment which shows what must be printed if your -# code works correctly. It also shows how many points the test is worth. -# - -try: - z = Zillion('') -except RuntimeError: - print('Empty string') - -# It must print 'Empty string' without apostrophes. 2 points. - -try: - z = Zillion(' , ') -except RuntimeError: - print('No digits in the string') - -# It must print 'No digits in the string' without apostrophes. 2 points. - -try: - z = Zillion('1+0') -except RuntimeError: - print('Non-digit in the string') - -# It must print 'Non-digit in the string' without apostrophes. 2 points. - -try: - z = Zillion('0') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print True. 2 points. - -try: - z = Zillion('000000000') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print True. 2 points. - -try: - z = Zillion('000 000 000') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print True. 2 points. - -try: - z = Zillion('997') -except RuntimeError: - print('This must not be printed') - -# It must print nothing. 2 points. - -print(z.isZero()) # It must print False. 2 points. - -print(z.toString()) # It must print 997. 2 points. - -z.increment() - -print(z.toString()) # It must print 998. 2 points. - -z.increment() - -print(z.toString()) # It must print 999. 2 points. - -z.increment() - -print(z.toString()) # It must print 1000. 2 points. - -try: - z = Zillion('0 9,9 9') -except: - print('This must not be printed') - -# It must print nothing. 3 points. - -z.increment() -print(z.toString()) # It must print 1000. 2 points. -- cgit v1.2.3