Skip to content

Instantly share code, notes, and snippets.

@CleverProgrammer
Created September 28, 2016 15:03
Show Gist options
  • Save CleverProgrammer/c9534970a9691bd87463b9820ed511f0 to your computer and use it in GitHub Desktop.
Save CleverProgrammer/c9534970a9691bd87463b9820ed511f0 to your computer and use it in GitHub Desktop.
Sort 3 integers in order and print them out using only 3 if statements at most.
def print_in_order(a, b, c):
if a >= b:
if b >= c:
print(c, b, a)
elif a >= c:
print(b, c, a)
else:
print(b, a, c)
else:
if a >= c:
print(c, a, b)
elif c >= b:
print(a, b, c)
else:
print(b, c, a)
print_in_order(3, 2, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment