-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxAndMinUnsortedArray.py
More file actions
35 lines (27 loc) · 899 Bytes
/
MaxAndMinUnsortedArray.py
File metadata and controls
35 lines (27 loc) · 899 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
import random
def get_min_max(ints):
"""
Return a tuple(min, max) out of list of unsorted integers.
Args:
ints(list): list of integers containing one or more integers
"""
if ints == []:
return None, None
min = ints[0]
max = ints[0]
for i in range(1, len(ints)-1):
if type(ints[i]) == str:
return "invalid input"
if ints[i] < min:
min = ints[i]
elif ints[i] > max:
max = ints[i]
return min, max
## Example Test Case of Ten Integers
l = [i for i in range(0, 10)] # a list containing 0 - 9
random.shuffle(l)
print ("Pass" if ((0, 9) == get_min_max(l)) else "Fail")
l1 = [8, 's', 3] # edge case: array with character
print ("Pass" if ("invalid input" == get_min_max(l1)) else "Fail")
l2 = [] # edge case: empty array
print ("Pass" if ((None, None) == get_min_max(l2)) else "Fail")