Python Forum
NEED HELP WITH NUMBER SORTER
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NEED HELP WITH NUMBER SORTER
#2
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.
Reply


Messages In This Thread
NEED HELP WITH NUMBER SORTER - by Paul_Choi06 - May-30-2020, 01:26 AM
RE: NEED HELP WITH NUMBER SORTER - by deanhystad - May-30-2020, 02:06 AM
RE: NEED HELP WITH NUMBER SORTER - by BitPythoner - May-30-2020, 02:20 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020