-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment_07.py
executable file
·81 lines (57 loc) · 1.76 KB
/
assignment_07.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
__author__ = 'Chaithra'
notes = '''
This is assignment covers functions and nested functions.
Read the comments and fill up the code. If the spec is not clear, read the tests below.
'''
from placeholders import *
# Fill up the higher order function below to return a function which
# can be used to test whether a number is greatherThan the specified
# value
def greater_than(value):
def compare(cmp):
if (value < cmp):
return True
else:
return False
return compare
# Fill up the negate function which returns a function that negates the output of the passed
# in function. The passed in function can take arbitrary number of
# positional args and returns True or False
def negate(func):
def func1(*args):
true_result = func(*args)
return not true_result
return func1
def test_greater_than():
g8 = greater_than(8)
assert True == g8(9)
assert False == g8(5)
assert False == g8(8)
g5 = greater_than(5)
assert True == g5(100)
assert False == g5(-1)
assert False == g5(5)
def test_negate():
def greater(a, b):
return a > b
result = negate(greater)
assert False == result(10, 9)
assert True == result(10, 10)
assert True == result(10, 11)
def equal(a, b):
return a == b
notequal = negate(equal)
assert False == notequal([10], [10])
assert False == notequal("hello", "hello")
assert True == notequal([], [10])
not_any = negate(any)
assert True == not_any([])
assert True == not_any([None, None])
assert False == not_any([10, ""])
assert False == not_any("hello")
three_things_i_learnt = """
-
-
-
"""
time_taken_minutes = ___