0

I am making a program to check how many even numbers there are in a list and printing the even numbers out. However, when I uncomment my last line to get user input, the program doesn't work anymore. But the second-to-the-last line does work. I am new to Python, how do I get my last line to work? I have researched but I still can't figure it out. Please help

evennums = []


def is_even(list):
    amount = 0
    for i in list:
        if i % 2 == 0:
            amount = amount + 1
            evennums.append(i)
    print(f"There are {amount} even numbers in this list. They are: {evennums} ")

#the following line works
is_even([1,2,3,4,10,11])

# The following line does not work
#is_even(int(input("Enter a list of numbers: ")))
philipxy
  • 14,867
  • 6
  • 39
  • 83
hershey10
  • 77
  • 4
  • 1
    Beause `int` returns a single integer, but your function requires a list of integers. – Barmar Feb 03 '22 at 02:30
  • 1
    The last line does not work because `int()` cannot return a list; it can only return a single integer. – John Gordon Feb 03 '22 at 02:31
  • 1
    I think you may find [this](https://stackoverflow.com/questions/4663306/get-a-list-of-numbers-as-input-from-the-user) very useful – 0x263A Feb 03 '22 at 02:34

0 Answers0