In: Computer Science
In python 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
# Store the multiple inputs for negative and non-negative
# integers into integer using split() method to get a
# list of strings separated by space.
integers = input().split()
# Define an empty list non_neg_int to store all
# non-negative integers.
non_neg_int=[]
# Use for loop to traverse through numbers stored in the
# integers list.
for num in integers:
# Convert the string number into integer.
num = int(num)
# Checks whether number is non-negative.
if num >= 0:
# Append the non_neg_int list with number.
non_neg_int.append(num)
# Sort the non_neg_int list in ascending order using
# sort() function.
non_neg_int.sort()
# Use for loop to print the sorted list of
# non-negative integers.
for i in non_neg_int:
# Display the non-negative integers followed by
# space in the end.
print(i,end=' ')