Skip to content

Commit ca3b09d

Browse files
committed
added a coding bat solution
1 parent 0df3e2e commit ca3b09d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
assert pos_neg(-4, -5, True) is True
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

Comments
 (0)