-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path38.py
31 lines (29 loc) · 825 Bytes
/
38.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
#Write a Python program that reads 5 numbers into a list and prints the second largest number and its location or index position on the list. [You are not allowed to use the max(), sort(), sorted() function here]
x = []
g = input("Enter 5 numbers: ").split(",")
for i in g:
x.append(int(i))
temp = None
count = 0
nlst = []
ntemp = None
count1 = 0
for i in range(len(x)):
if temp == None:
temp = x[i]
elif temp < x[i]:
temp = x[i]
count = i
for i in range(len(x)):
if x[i] != temp:
nlst.append(x[i])
for p in range(len(nlst)):
if ntemp == None:
ntemp = nlst[p]
elif ntemp < nlst[p]:
ntemp = nlst[p]
count1 = p
print(ntemp)
print(count1)
print(f"My list: {ff} ")
print(f"Second largest number in the list is {mx1} which was found at index {t}")