Purify


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/2?curriculum_id=4f89dab3d788890003000096#


Your function crashed on [1] as input because your function throws a "'int' object is not iterable" error.

I dont understand why this doesnt work

This code runs fine on Sumblime text (this is what i use for editing and problem solving before typing into the website.

Is there a difference between the codeacedmy compilers and the ones used from sublimetext?.... I know the code is not elegant (but I am learning as you can guess).

please help!


def purify(numbers):
	count = 1
	nocount = 0
	if (len(numbers) != 1):
		for i in numbers:
			if (i % 2 == 0):
				return i
	else: 
		if (numbers[0] % 2 == 0):
			return count
		else:
			return nocount.


#2

did you add function calls to execute your function when working outside codecademy?

sublime text is only a text-editor, it doesn't actually run the python code

python is an interpreted language, not a compiled one


#3

Yes I know, but I got the Terminal Package which brings up the part to run it... I get the right prints when I do this.


#4

the error in the lesson is a bit misleading, lets look at it:

def purify(numbers):
	count = 1
	nocount = 0
	if (len(numbers) != 1):
		for i in numbers:
			if (i % 2 == 0):
				return i
	else: 
		if (numbers[0] % 2 == 0):
			return count
		else:
			return nocount
print purify([1])

this will output 0, it should output []

the exercise wants you to return a list with only even numbers remaining, if there are only odd numbers a empty list should be returned


#5

so my code is fine, i just need to out put a blank list not a 0?


#6

yes


#7

you should create a new list and return it. that's what the exercise asks.


#8

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