Nov-14-2019, 12:32 AM
Hi, I'm trying to sort this "List' of values that contains both negative and positive numbers. I'm trying to sort in numerical order from least to the greatest value using a double for loop and swapping variables. However, I ran into some errors when running my code, and I think it's because of the negative values in the "List" array. How do I get around this problem?
Here is my Python code that I have written so far:
Here is my Python code that I have written so far:
numbers = [11.5, 28.3, 23.5, -4.8, 15.9, -63.1, 79.4, 80.0, 0, 67.4, -11.9, 32.6] length_numbers = len(numbers) for i in numbers: for j in range (0, length_numbers): if numbers[j] > numbers[j+1]: temp = numbers[j] numbers[j] = numbers[j+1] numbers[j+1] = temp print(numbers)