Skip to content

Instantly share code, notes, and snippets.

@mhassanist
Last active August 16, 2021 09:17
Show Gist options
  • Save mhassanist/e65e09cb0316cb0c261f1d064ec8927a to your computer and use it in GitHub Desktop.
Save mhassanist/e65e09cb0316cb0c261f1d064ec8927a to your computer and use it in GitHub Desktop.
#assume no value for max and second max.
#You may also assume a very small numbers that u r sure will not be in the input data.
maximum = None
second_max = None
for i in range(5):
num = int(input('Enter a number: '))
if i == 0:
maximum = num #consider the first number as the max
continue #skip to the second number
#starting from second number
if num > maximum:
second_max = maximum
maximum = num
elif num == maximum:
continue
elif num < maximum and (second_max == None or num > second_max):
second_max = num
print(second_max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment