You are on page 1of 3

s = input()

lst = []

for x in s.split(" "):

if int(x)>0:

lst.append(int(x))

lst.sort()

for x in lst:

print(x,end=" ")

print()

I think in question 0 is to be included, so in code make it if int (x) >=0;

Code 2

# 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=' ')

Code 3
our_input = [int(our_input) for our_input in input("Enter value Seperated By Space: ").split()]#get
all that input from user
new_input=[]#take new empty input list
for i in our_input:
if(i>0):
new_input.append(i)
new_input.sort()#sort asendering here
for i in new_input:
   print(i,end = ' ')

code 4

#Prompt the user to enter numbers on a single line

#separated by space.

num_values = input()
#Split those numbers through spaces, store the numbers

#which are greater than 0 (non-negative integers) into

#a list by converting the values to int.

list_values = [int(num) for num in num_values.split()

if int(num) >=0]

#Apply the sort() function over list of values to sort

#the values in ascending order.

list_values.sort()

#Display the sorted list of positive integers with

#spaces between them.

for value in list_values:

    print(value, end = ' ')

You might also like