Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read a line of integers and print them sorted ascending, space-separated.
sorted() returns a new list. list.sort() edits in place. Either is fine here.
Input. One line: integers separated by spaces.
Output. The same values, ascending, space-separated.
Examples
Input
5 3 1 4 2
Output
1 2 3 4 5
Input
3 3 1
Output
1 3 3
Hint
- print(*sorted(nums))
- Negatives sort before positives in Python.
Show correct code
Peek only after you have tried. You can still Check your own version.
nums = list(map(int, input().split()))
print(*sorted(nums))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.