Created
December 10, 2012 16:14
-
-
Save Ivoah/4251563 to your computer and use it in GitHub Desktop.
Sort
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
import sys | |
s = {} | |
for i in range(1, 6): | |
s[i] = sys.maxsize | |
for i in range(5): | |
while True: | |
try: | |
x = raw_input('Enter int #%s: ' %i) | |
x = int(x) | |
break | |
except ValueError: | |
print 'You must enter a valid integer.' | |
if x < s[1]: | |
s[5] = s[4] | |
s[4] = s[3] | |
s[3] = s[2] | |
s[2] = s[1] | |
s[1] = x | |
elif x < s[2]: | |
s[5] = s[4] | |
s[4] = s[3] | |
s[3] = s[2] | |
s[2] = x | |
elif x < s[3]: | |
s[5] = s[4] | |
s[4] = s[3] | |
s[3] = x | |
elif x < s[4]: | |
s[5] = s[4] | |
s[4] = x | |
elif x < s[5]: | |
s[5] = x | |
for i in range(1, 6): | |
print s[i] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment