-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq4.py
31 lines (23 loc) · 752 Bytes
/
q4.py
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
def second_smallest_finder(num):
min_val = 100
sec_min = 100
for i in range(len(num)):
if num[i] < min_val:
min_val = num[i]
for i in range(len(num)):
if (num[i] < sec_min) and (num[i] != min_val):
sec_min = num[i]
return(sec_min)
def second_largest_finder(num):
max_val = -100
sec_max = -100
for i in range(len(num)):
if num[i] > max_val:
max_val = num[i]
for i in range(len(num)):
if (num[i] > sec_max) and (num[i] != max_val):
sec_max = num[i]
return(sec_max)
num = [1,2,-8,-2,0]
print("(a) Second Smallest Number :", second_smallest_finder(num))
print("(b) Second largest Number :", second_largest_finder(num))