Purify


#1



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:
            purified.append(i)
            
    return purified
        
numbers = list(raw_input("Enter the list here: "))
print purify(numbers)


#2

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


#3

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


#4

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?))


#5

this will work

def purify(num):
val=[]
for i in num:
if i%2 == 0:
val.append(i)

return val

#6

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