Sorting numbers | Ascending or Descending | Python Program.

Python Program to sort a list of user given numbers either in Ascending order or in Descending order.


Code :

num = (input("Enter numbers with space in betweens :\n> ").split(" "))
choice = input('(A)scending or (D)escending :>  ').lower()
if choice == 'a':
    num.sort(key=int)
    for x in num:
        print(x, end=' ')
elif choice == 'd':
    num.sort(key=int)
    num.reverse()
    for x in num:
        print(x,end=' ')

 Output :

Ascending order -

Decending order -


Comments

Popular posts from this blog

Print Fibonacci Series using Recursion | C program :

Speech Recognition | Python Program