-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmonkey_trouble.py
More file actions
56 lines (44 loc) · 1.28 KB
/
monkey_trouble.py
File metadata and controls
56 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
#############################
# Warmup-1 > monkey_trouble
def monkey_trouble(a_smile, b_smile):
"""
really simple solution
"""
if a_smile and b_smile:
return True
elif not a_smile and not b_smile:
return True
else:
return False
def monkey_trouble2(a_smile, b_smile):
"""
slightly more sophisticated
"""
if a_smile and b_smile or not (a_smile or b_smile):
return True
else:
return False
def monkey_trouble3(a_smile, b_smile):
"""
conditional expression -- kind of ugly in this case
"""
result = True if (a_smile and b_smile or not (a_smile or b_smile)) else False
return result
def monkey_trouble4(a_smile, b_smile):
"""
direct return of boolean result
"""
return a_smile and b_smile or not (a_smile or b_smile)
if __name__ == "__main__":
# a few tests
# neat trick to test all versions:
for test_fun in (monkey_trouble,
monkey_trouble2,
monkey_trouble3,
monkey_trouble4):
assert test_fun(True, True) is True
assert test_fun(False, False) is True
assert test_fun(True, False) is False
assert test_fun(False, True) is False
print("All tests passed")