Write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest). Ex: If the input is: 10 -7 4 39 -6 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space. Do not end with newline. My Code: int_list = str(input()) int_list = int_list.split() for i in range(0, len(int_list)): int_list[i] = int(int_list[i]) int_list.sort() i = 0 while i <= len(int_list): if int_list[i] < 0: int_list.remove(int_list[i]) print('{}'.format(int_list)) I keep getting an error code stating that the program could not be run to complication and the output is giving me: [-6, 2, 4, 10, 12, 39] [2, 4, 10, 12, 39], I dont understand why it's give me the list twice when I only have one print statement
Write a
Ex: If the input is:
10 -7 4 39 -6 12 2
the output is:
2 4 10 12 39
For coding simplicity, follow every output value by a space. Do not end with newline.
My Code:
int_list = str(input())
int_list = int_list.split()
for i in range(0, len(int_list)):
int_list[i] = int(int_list[i])
int_list.sort()
i = 0
while i <= len(int_list):
if int_list[i] < 0:
int_list.remove(int_list[i])
print('{}'.format(int_list))
I keep getting an error code stating that the program could not be run to complication and the output is giving me: [-6, 2, 4, 10, 12, 39] [2, 4, 10, 12, 39], I dont understand why it's give me the list twice when I only have one print statement
![](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc00246d7-210d-47f4-964d-360b3bcbb90b%2F6d62f9e3-54e3-407e-9120-9de612e50dac%2F2cm0kkg.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)