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=' ')
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)