-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmin-array.py
More file actions
28 lines (20 loc) · 721 Bytes
/
min-array.py
File metadata and controls
28 lines (20 loc) · 721 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
def smallest_positive(in_list):
# TODO: Define a control structure that finds the smallest positive
# number in in_list and returns the correct smallest number.
temp = -1;
for i, value in enumerate (in_list):
if(temp < 0 and value > 0):
temp = value
if(value < temp and value > 0):
temp = value
if temp > 0:
return temp;
else:
return None
# Test cases
print(smallest_positive([4, -6, 7, 2, -4, 10]))
# Correct output: 2
print(smallest_positive([.2, 5, 3, -.1, 7, 7, 6]))
# Correct output: 0.2
print(smallest_positive([-33.04, 48.83, 75.33, 39.82, 76.38, 98.41, 71.27, 67.84, -16.58]))
print(smallest_positive([-1,-2,-3]))