[Python] Filter and sort inputed list of integers for non negative numbers python

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to take a list that a user inputs, filter and sort in ascending order but only for the non-negative numbers. I thought I understood how to do this but it will not work with my logic.

    my_list = []
    n = int(input())
    for i in range(0, n):
    element = int(input())
    if element > 0:
    my_list.append(element)
    my_list.sort()
    print(my_list)


    Here is the error I receive: ValueError: invalid literal for int() with base 10: '10 -7 4 39 -6 12 2' It doesn't like line 2

    Continue reading...

Compartilhe esta Página