In: Computer Science
a) Write a program that reads a list of integers, and outputs all even integers in the list. For example, if the input list is [1, 2, 13, 14, 25], the output list should be [2, 14].
b) Based on your code for part (a), write a program that reads a list of integers, and reports True if all numbers in the list are even, and False otherwise. Example: For input [1, 2, 13, 14, 25], the output should be False.
Your program must define and call the following two functions.
evens() returns all even integers in the list are even.
all_even() returns True if all integers in the list are even and false otherwise.
Your code could look like this
#Your name here
def evens(thelist):
#your code goes here
def all_even(thelist):
#your code goes here
evens([1, 2, 13, 14, 25]) #should return [2,14]
all_even([1, 2, 13, 14, 25]) #should return False
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== def evens(thelist): evens_l = [] for num in thelist: if num % 2 == 0: evens_l.append(num) return evens_l def all_even(thelist): return len(evens(thelist)) == len(thelist) def main(): thelist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print('The List:', thelist) print('Evens in the list:', evens(thelist)) print('Is all even?', all_even(thelist)) print('Is all even?', all_even(evens(thelist))) # passing the even list to check if its all evens main()
=============================================================