May-30-2020, 02:06 AM
(This post was last modified: May-30-2020, 02:06 AM by deanhystad.)
You are not sorting numbers. You are sorting strings. That is why it doesn't appear to work for numbers with 2 or more digits. To sort numbers you need to convert the strings to numbers.
Your code to get the numbers is odd and it is not doing what you think it does. Python has commands for splitting a string into tokens based on a delimiter (str.split). If you want commas and spaces between the numbers I would pick comma as the delimiter. To convert the strings to numbers you use int(str) or float(str). Both of these ignore leading or trailing spaces, but they do not like commas.
The print('') is causing the blank space between you input and output.
Your code to get the numbers is odd and it is not doing what you think it does. Python has commands for splitting a string into tokens based on a delimiter (str.split). If you want commas and spaces between the numbers I would pick comma as the delimiter. To convert the strings to numbers you use int(str) or float(str). Both of these ignore leading or trailing spaces, but they do not like commas.
The print('') is causing the blank space between you input and output.