File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Solutions/Session01/codingbat/Warmup-1 Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments