Respuesta :
nums = input("Enter your numbers: ")
lst = nums.split()
new_lst = ([])
for i in lst:
if int(i) >= 0:
new_lst.append(int(i))
new_lst.sort()
for x in new_lst:
print(x, end=" ")
The above code is in case the user enters the numbers.
def func(lst):
lst.sort()
for i in lst:
if i >=0:
print(i, end=" ")
lst = ([10,-7, 4, 39, -6, 12, 2])
func(lst)
The above code is in case you must input the numbers manually via a function.
I hope this helps!
This program will make use of lists, for loop iterations and if statements. The lists are used for inputs, the for loop are used to iterate through the input values, while the if statements are used to get the right filtered value.
The program make use of comments to explain each line.
The program in Python is as follows:
#This gets the input from the user
inputNum = input("Input all numbers separated by space: ")
#This splits the input numbers into a list
listNum = inputNum.split()
#This sorts the list
listNum.sort()
#Here, we iterate through the list
for num in listNum:
#This checks if current list element is non-negative
if int(num) >= 0:
#If yes, the list element is printed followed by a space
print(num,end=" ")
Read more about lists at:
https://brainly.com/question/15092271