-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxnum.py
More file actions
37 lines (25 loc) · 669 Bytes
/
maxnum.py
File metadata and controls
37 lines (25 loc) · 669 Bytes
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
"""Return the largest integer in a list.
Given a list of integers, return the largest. Do not use the built in 'max' method.
For example::
>>> max_num([1, 3, 2, 4, 7, 2])
7
>>> max_num([5, 5, 5])
5
>>> max_num([10])
10
>>> max_num([-1, -2, -3])
-1
>>> max_num([-10, 0])
0
"""
def max_num(num_list):
"""Returns largest integer from given list"""
max_so_far = num_list[0]
for num in num_list:
if num > max_so_far:
max_so_far = num
return max_so_far
if __name__ == '__main__':
import doctest
if doctest.testmod().failed == 0:
print "\n*** ALL TESTS PASSED. GO YOU!\n"