Last active
August 16, 2021 09:17
-
-
Save mhassanist/e65e09cb0316cb0c261f1d064ec8927a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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