Why doesnt this work? Should I convert it into a list separately?
This is the error that it shows : line 4, in purify
TypeError: not all arguments converted during string formatting

def purify(numbers):
    purified = []
    for i in numbers:
        if i%2 == 0:
    return purified
numbers = list(raw_input("Enter the list here: "))
print purify(numbers)


What type does your function expect as input and what are you giving it?


Its expecting a list. That's why I converted the raw input into a list.


A list of what though? What should that list look like?

>>> list('5 116 27 8')
['5', ' ', '1', '1', '6', ' ', '2', '7', ' ', '8']

Before starting to think of a solution to a problem it's necessary to establish what the problem is, so one has to have a look at what was done.

And then, before thinking about what code to write, what would be actions required to massage that into what's wanted? (Keep in mind that those actions can't leave anything out, they need to be pretty detailed and complete, so for example "convert them to numbers" doesn't say what to convert to numbers (the spaces?))


this will work

def purify(num):
for i in num:
if i%2 == 0:

return val


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.