[Tutor] Odd & Even lists
Mary Knauth
maryknauth at mac.com
Sat May 30 10:06:56 EDT 2020
Hello,
I am working through a Python course, and I’m really stuck on working with lists. The script I am working on now is:
Task:
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
Current code I am running:
# Get our input from the command line
import sys
numbers = sys.argv[1].split(',')
for i in range(0,len(numbers)): # 0 to the length of the list
numbers[i]= int(numbers[i]) # creates a list of numbers and converts numberes to an integer
# Modulo operator to decifer even numbers
def isEven(n) :
return ((n % 2) == 0) # n % 2 leaves no remainder, therefore even
for i in range(numbers)
if i == isEven:
def listEven = [i]
else:
def listOdd = [i]
print(listOdd)
listOdd.append(i)
print(listEven)
listEven.append(i)
Any advice in the right direction is appreciated, thank you!
Warm Regards,
Mary
http://www.zephyrsolutions.us <http://www.zephyrsolutions.us/>
<https://zephyrsolutions.us/>
More information about the Tutor
mailing list