15,615,280 members
0.00/5 (No votes)
See more:
I am creating a program that sorts the user's input in increasing and decreasing order... I have tried the sorted() function but it would only sort 1 number.

What I have tried:

Python
```list=input("Enter your list:")
print("Unsorted:", list.split())

a=list
print("Sorted Ascending Order:")
print sorted(a)

print("Sorted Descending Order:")
print sorted(a, reverse=True)```

In my code, I tried to sort 35,5 and 4 but the result would be like this:
`['3','4','5','5']`
Posted
Updated 13-Apr-21 1:03am
v3

## Solution 1

The following program (`Python 3`)
Python
```s = input()
lnum = list(map(int, s.split()))

print("Unsorted:", lnum)

print("Sorted Ascending Order:")
print (sorted(lnum))

print("Sorted Descending Order:")
print(sorted(lnum, reverse=True))```

executes this way
```35 5 4
Unsorted: [35, 5, 4]
Sorted Ascending Order:
[4, 5, 35]
Sorted Descending Order:
[35, 5, 4] ```

Comments
lil_mint 13-Apr-21 10:34am
Thank you very much, this helps a lot..
CPallini 13-Apr-21 10:50am
You are welcome.
Maciej Los 13-Apr-21 15:52pm
5ed!
CPallini 14-Apr-21 1:45am
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 195 Richard MacCutchan 115 raddevus 75 Dave Kreskowiak 48 Rick York 30
 OriginalGriff 3,116 Richard MacCutchan 1,381 Graeme_Grant 965 Dave Kreskowiak 689 CHill60 385

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900