0

# I need a function that counts odds and even numbers in a list. This is what I have so far

#create an empty list named nums. #use a loop to add 10 random integers, all in the range from 1-25, to the list. #use another loop to display the numbers all on the same line, separated by a single space. #sort the list. #use another loop to display the sorted numbers all on the same line, separated by a single space. #make a new list named start by slicing out the first 4 elements of the sorted nums list. #print the start list. #make a new list named finish by slicing out the final 5 elements of the sorted nums list. #print the finish list. #execute the odd_even function (defined next) with sorted nums as its sole argument. import random def main(): #empty list named nums nums = [] #loop to add 10 random integers, in range of 1-25 for n in range (10): nums.append(random.randint(1,25)) #loop display sorted numbers all on same line with single space for num in nums: print(num,end=' ') print('\n') #display list of numbers in reverse for num in reversed(nums): print(num,end=' ') print('\n') start_list = nums[4:] print (start_list, end='') print('\n') finish_list = nums[:5] print(finish_list, end='') def evenOdd(nums): print("Evens:", nums(range(2, nums + 1, 2))) print("Odds:", nums(range(1, nums + 1, 2))) main() Please help I'm so close its killing me

1st Oct 2017, 7:23 AM
Reginald Wright
1 Respuesta
0
use filter funtion will help you. just make google search for it. anyway you will learn it in python course when you reach functional programming
2nd Oct 2017, 1:53 PM
Kevin AS