sort three numbers in descending order using Python

Accept 3 numbers in 3 individual variables and sort in descending order:

def find_highest():
a,b,c=(13,222,24) # This can be taken as run time input.
print "\nNumbers are:",a,b,c

if a>b:
if a>c:
if b>c:
print "\n%d %d %d" %(a,b,c)
else:
print "\n%d %d %d" %(a,c,b)
elif a<c:
print "\n%d %d %d" %(c,a,b)
else:
if a<c:
if b<c:
print "\n%d %d %d" %(c,b,a)
else:
print "\n%d %d %d" %(b,c,a)
elif a<c:
print "\n%d %d %d" %(b,a,c)

if __name__ == "__main__":
find_highest()

Advertisements
Post a comment or leave a trackback: Trackback URL.

Comments

  • sam  On June 26, 2015 at 9:16 am

    I have simpler methods.

    Hope you will like it

    >>> a = [1,2,4,5]
    >>> sorted(a)
    [1, 2, 4, 5]
    >>> sorted(a, reverse=True)
    [5, 4, 2, 1]
    >>> a.sort()
    >>> a
    [1, 2, 4, 5]
    >>> a.sort(reverse=True)
    >>> a
    [5, 4, 2, 1]
    >>>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: