0

I am creating a program that takes a list of user inputted integers and returns only the positive values in a list. My code is as follows:

def positive_numbers():
    user_input = [int(input('Enter a positive number:'))]
    numbers = []
    for i in user_input:
        if i >= 0:
            numbers.append(i)
        return numbers

When I call the function with print(f'{positive_numbers()}') I get this error when inputting a list of values: ValueError: invalid literal for int() with base 10: '1 2 4 56 -22 45' I believe my issue resides woth the initial user input list, how would I fix this?

  • 1
    In the future, please include the [full error message with traceback](https://meta.stackoverflow.com/q/359146/4518341). In this case it's obvious *where* the issue is occurring, but in other cases, it might not be. It also helps to include the desired output. See [mre] for more info. BTW, if you want more tips, check out [ask]. – wjandrea Mar 12 '22 at 16:41
  • 1
    BTW, `return numbers` is indented one level too far – wjandrea Mar 12 '22 at 16:41

0 Answers0