forked from wadehuber/codeexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
51 lines (41 loc) · 1.38 KB
/
Copy pathfunctions.py
File metadata and controls
51 lines (41 loc) · 1.38 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
''' Writing functions in Python '''
def say_hello() :
''' Function with no return '''
print("Hello!")
def add_ten(xparm) :
''' Function that returns a value '''
return xparm + 10
def add_twenty(xparm) :
''' Function that modifies a parameter '''
xparm = xparm + 20
def add_array(arr) :
''' Function that sums a list '''
total = 0
for value in arr:
total += value
return total
def enumerate_array(arr) :
''' Function that prints index/value pairs of a list '''
for index, value in enumerate(arr):
print("[{}] = {}".format(index, value))
def main() :
''' Main method for the module '''
aval = 5
bval = 0
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
say_hello()
print("a={}, b={}".format(aval, bval))
print("add_ten(a)={}, add_ten(b)={}".format(add_ten(aval), add_ten(bval)))
print("a={}, b={}".format(aval, bval))
print("add_twenty(b)")
add_twenty(bval)
print("a={}, b={}".format(aval, bval))
print("add_ten(a)={}, add_ten(b)={}".format(add_ten(aval), add_ten(bval)))
print("a={}, b={}".format(aval, bval))
print("arr: {}".format(arr))
print("add_array(arr)={}".format(add_array(arr)))
print("enumerate_array(arr):")
format(enumerate_array(arr))
# This code checks to see if this module is being run (versus imported). If so, it calls main
if __name__ == '__main__' :
main()