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
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images