Oct-26-2018, 02:17 PM
The way you implement the function it returns on line 15 and line 16 never get executed. You need to return both even_numbers and odd_numbers simultaneously.
import random original_list = [random.randint(1,1000) for x in range(0,100)] print("Original list:", original_list) def oddandeven(numbers_list): even_numbers = [] odd_numbers = [] for number in numbers_list: if number % 2 == 0: even_numbers.append(number) else: odd_numbers.append(number) return even_numbers, odd_numbers even, odd = oddandeven(original_list) print("Odd: {}".format(odd)) print("Even: {}".format(even)) # you can replace above 3 lines with print("Even: {}\nOdd: {}".format(*oddandeven(original_list)))Like this your function would return tuple, which means even numbers will always be first element and odd numbers - second. You may want to return dict instead, which will allow to retrieve respective list by key
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs