aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913
diff options
context:
space:
mode:
Diffstat (limited to 'csci1913')
-rw-r--r--csci1913/Python/lab1_strap012.py (renamed from csci1913/lab1/lab1_strap012.py)0
-rw-r--r--csci1913/Python/lab2_strap012.py (renamed from csci1913/lab1/lab2_strap012.py)45
2 files changed, 36 insertions, 9 deletions
diff --git a/csci1913/lab1/lab1_strap012.py b/csci1913/Python/lab1_strap012.py
index 396fda9..396fda9 100644
--- a/csci1913/lab1/lab1_strap012.py
+++ b/csci1913/Python/lab1_strap012.py
diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/Python/lab2_strap012.py
index 34fbe6a..4e154f7 100644
--- a/csci1913/lab1/lab2_strap012.py
+++ b/csci1913/Python/lab2_strap012.py
@@ -1,20 +1,47 @@
class Zillion:
def __init__(self,digits):
self.digits = digits
- if (1==1):
- try:
- int(digits)
- except ValueError:
- raise RuntimeError
+ 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):
- return int(self.digits)+1
+ 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 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:
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]) #Make string by concatenation
+ return string