aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2019-09-18 14:58:25 -0500
committerMatthew Strapp <msattr@gmail.com>2019-09-18 14:58:25 -0500
commit93c42e431110ab54ec9b13d4400ca338f15d8721 (patch)
tree371d4ab052519e371d5dfa5a26d019228766bd41 /csci1913
parentIt's in his scrawny hands (diff)
downloadhomework-93c42e431110ab54ec9b13d4400ca338f15d8721.tar
homework-93c42e431110ab54ec9b13d4400ca338f15d8721.tar.gz
homework-93c42e431110ab54ec9b13d4400ca338f15d8721.tar.bz2
homework-93c42e431110ab54ec9b13d4400ca338f15d8721.tar.lz
homework-93c42e431110ab54ec9b13d4400ca338f15d8721.tar.xz
homework-93c42e431110ab54ec9b13d4400ca338f15d8721.tar.zst
homework-93c42e431110ab54ec9b13d4400ca338f15d8721.zip
I want to be kill
Diffstat (limited to 'csci1913')
-rw-r--r--csci1913/lab1/lab2_strap012.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/csci1913/lab1/lab2_strap012.py b/csci1913/lab1/lab2_strap012.py
new file mode 100644
index 0000000..67dcceb
--- /dev/null
+++ b/csci1913/lab1/lab2_strap012.py
@@ -0,0 +1,111 @@
+class Zillion:
+ def __init__(self,digits):
+ self.digits = digits
+ try:
+ int(digits)
+ except ValueError:
+ raise RuntimeError
+ # for n in range (0,len(str(digits))):
+ # test[n]=str(digits)[n]
+ def increment(self):
+ return 1
+ def isZero(self):
+ for n in range (0,len(str(digits))):
+ if digits[n] is not 0:
+ return False
+ return True
+ def toString(self):
+ return str(self)
+
+
+
+#
+# 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.