1 parent 0df3e2e commit ca3b09dCopy full SHA for ca3b09d
1 file changed
Solutions/Session01/codingbat/Warmup-1/pos_neg.py
@@ -0,0 +1,27 @@
1
+#!/usr/bin/env python
2
+
3
4
+def pos_neg(a, b, negative):
5
+ if negative:
6
+ return a < 0 and b < 0
7
+ else:
8
+ return (a < 0 and b > 0) or (a > 0 and b < 0)
9
10
+if __name__ == "__main__":
11
+ # run some tests if run as script
12
+ # (from the codingbat site -- not all, I got bored)
13
+ assert pos_neg(1, -1, False) is True
14
+ assert pos_neg(-1, 1, False) is True
15
+ assert pos_neg(-4, -5, True) is True
16
+ assert pos_neg(-4, -5, False) is False
17
18
19
+ assert pos_neg(-6, -6, False) is False
20
+ assert pos_neg(-2, -1, False) is False
21
+ assert pos_neg(1, 2, False) is False
22
+ assert pos_neg(-5, 6, True) is False
23
+ assert pos_neg(-5, -5, True) is True
24
25
26
27
+ print "all tests passed"
0 commit comments