I know there are answers to this question, but the problem I am having with my code is that it works for most occasions except when it prints out the max number. As long as the first two numbers or more in the list are the max. It may sound confusing, but here's my code with an example.
def s_max(l):
pos = 0
m1 = max(l)
m2 = 0
for i in l:
pos += 1
if i > m2 and i != m1:
m2 = i
elif m2 == 0 and i == m1 and pos > 1:
m2 = m1
elif i < m1 and i <= m2:
i = m2
else:
m2 = m2
print(m2)
s_max([10,10,9])
OUTPUT = 10
When I use a list of numbers such as [9,10,10], the code will output 9.