Question: Write a function that takes in a list of integers and returns a list containing either all the odd numbers or all the even numbers

Write a function that takes in a list of integers and returns a list containing either all the odd numbers or all the even numbers in the list. The function should have two parameters: the list of integers, and a string (either odd or even) that determines if the function should return all the odds or all the evens. If a user does not pass in a second argument (the string even or odd), the function should default to returning all evens.

If there is something in the list that is not an integer, raise a ValueError and tell the user that this function can only take in lists of integers.

Make sure to give your function a descriptive name and a good docstring.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!