forked from adaptives/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_functions.py
More file actions
executable file
·60 lines (43 loc) · 1 KB
/
python_functions.py
File metadata and controls
executable file
·60 lines (43 loc) · 1 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
57
58
59
60
#!/usr/bin/python
maxCalled = 0
minCalled = 0
def max_val(a,b):
'''Returns the maximum of the specified arguments.
Arguments must be numbers'''
global maxCalled
maxCalled = maxCalled + 1
if(a > b):
return a
elif(b > a):
return b
else:
return a
def min_val(a,b):
'''Returns the minimum of the specified arguments.
Arguments must be numbers'''
global minCalled
minCalled = minCalled + 1
if(a < b):
return a
elif(b < a):
return b
else:
return a
def print_usage(init_msg, max_val=True, min_val=True):
global maxCalled, minCalled
print init_msg
if max_val:
print 'functin max_val was called', maxCalled, ' times'
if min_val:
print 'function min_val was called', minCalled, ' times'
print 'Calling function max_val'
print max_val.__doc__
max_val(1,4)
max_val(2,b=1)
max_val(b=4,a=3)
print 'Calling function min_val'
print min_val.__doc__
min_val(1,4)
min_val(2,4)
min_val(4,b=9)
print_usage('The usage of functions min_val and max_val')