summaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorraylu <raylu@cmu.edu>2011-05-13 18:14:58 -0400
committerraylu <raylu@cmu.edu>2011-05-13 18:14:58 -0400
commitf564a4616beead043e1568f22f5ef908af601afb (patch)
tree4d55d27f0c3d022b04a00551af5f7c4bf3178fda /static
parentd31422d4908dcb0d63b372ce9c10e371a0b4113c (diff)
downloadpyc-f564a4616beead043e1568f22f5ef908af601afb.tar.xz
Lab 2!
Diffstat (limited to 'static')
-rw-r--r--static/lab2.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/static/lab2.py b/static/lab2.py
new file mode 100644
index 0000000..a7dd654
--- /dev/null
+++ b/static/lab2.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+# Normally, there won't be two assignments overlapping, but we're still testing
+# so whatever.
+
+# total should return the sum of the numbers passed in
+def total(numbers):
+ return numbers[0]
+
+# onestring should return 1 the first time it's called and 'ring' the second time
+def onestring():
+ return 1
+
+# Your code will be run in a sandbox, so print statements are not allowed in
+# the required functions. The below code gets executed when you run the python
+# file; this should aid you in debugging/testing.
+if __name__ == '__main__':
+ list1 = [1, 2, 3]
+ list2 = [-10, -10, -30]
+ print 'sum of list1:', total(list1)
+ print 'sum of list2:', total(list2)
+
+ print # blank line
+
+ if onestring() == 1:
+ print 'got 1 the first time!'
+ else:
+ print 'onestring didn\'t return 1 the first time :('
+ if onestring() == 'ring':
+ print "got 'ring' the second time!"
+ else:
+ print "onestring didn't print 'ring' the second time D:"