My code is giving me a name not defined error:
Traceback (most recent call last): File "split.py", line 22, in print(even)
NameError: name 'even' is not defined
Here's the instructions, and what I have written.. if someone could point me in the right direction it would be appreciated.
instructions: We are passing in a list of numbers. You need to create 2 new lists in your chart, then:
- put all odd numbers in one list
- put all even numbers in the other list
- output the odd list first, the even list second
Tip: you should use the modulo operator to decide whether the number is odd or even. We provided a function for you to call that does this.
Don’t forget to define the 2 new lists before you start adding elements to them.
# Get our input from the command line
import sys
numbers = sys.argv[1].split(',')
for i in range(0,len(numbers)):
numbers[i]= int(numbers[i])
def isEven(n) :
return ((n % 2) == 0)
def Split(numbers):
even = [ ]
odd = [ ]
for i in numbers:
if i == isEven:
even.append(i)
else:
odd.append(i)
print(even) # <= error here: NameError: name 'even' is not defined
print(odd)