Printing "unsupported operated type" error when try to use % with list data?

42 Views Asked by At

Sorry, new to python in general. I'm making a code which separates a even,odd numbers from a num_list and even numbers would be sorted by highest to lowest. I'm keep getting "unsupported operated type" error message. Is there a way to use % with list?

num_list = [2,10,2,3,4,8,11]
odd_num = []
even_num = []


def number_seperator(*args):
    for i in args:
        if i % 2 == 0:
            return even_num.append(i)
        else:
            return odd_num.append(i)
    return 


print(max(number_seperator(num_list)))
print(even_num)
print(odd_num)
1

There are 1 best solutions below

0
AudioBubble On

You cannot take the modulus of a list.

You are currently trying to execute

if [2,10,2,3,4,8,11] % 2 == 1:
   ...

Decide whether you want to accept a single list parameter, or accept multiple int arguments. Them either delete the * in the def or add one to the method call.