How to sort 10 integers in python?

Question:

I am a novice programmer and have been struggling with some simple problems for too long

The pictures are sample details
1

Asked By: 599 Mighty

||

Answers:

It depends if you can use built-in functions of python such as sort().
If you can then you need an input to get all the values from the user. Apparently you are struggling on sorting them instead of retrieving them, in this case it is better to store them into lists (so your data looks like [4, 85, 3, 234, 45, …]).
Then you can use the sort() function to sort the list.
After that you can do a

for in in range(len(listName)):

    print(listName[i]

And you will have the output asked.

Answered By: Jacques Célère

Assuming you’re taking user (keyboard) input, then you could do this:

indata = input('Enter some integers separated by space: ')
print(*sorted(map(int, indata.split())), sep='n')

Output:

Enter some integers separated by space: 4 85 3 234 45 345 345 122 30 12
3
4
12
30
45
85
122
234
345
345

What this does…

Gets a string from the standard input. Split the string into tokens delimited by whitespace. Convert each token to an int. Sort the output from the map() object and print

Answered By: OldBill
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.