Python Code: Problem 4 – Any/all, filtering, counting [5×5 points] For this problem, you should define all functions wit

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Python Code: Problem 4 – Any/all, filtering, counting [5×5 points] For this problem, you should define all functions wit

Post by answerhappygod »

Python Code:
Problem 4 – Any/all, filtering, counting [5×5 points] For this
problem, you should define all functions within the even library
module. All functions in this problem should accept the same kind
of argument: a list of integers. Furthermore, all functions that we
ask you to define perform the same condition test over each of the
list elements (specifically, test if it’s even). However, each
returns a different kind of result (as described below). Finally,
once again none of the functions should modify their input list in
any way.
Remark: Although we do not require you to re-use functions in a
specific way, you might want to consider doing so, to simplify your
overall effort. You may define the functions in any order you wish
(i.e., the order does not necessarily have to correspond to the
sub-problem number), as long as you define all of them
correctly.
Problem 4.1 – even.keep(): Should return a new list, which
contains only those numbers from the input list that are even.
Problem 4.2 – even.drop(): Should return a new list, which
contains only those numbers from the input list that are not
even.
Problem 4.3 – even.all(): Should return True if all numbers in
the input list are even, and False otherwise. Just to be clear,
although you should not be confusing data types by this point, the
returned value should be boolean.
Problem 4.4 – even.any(): Should return True if at least one
number in the input list is even, and False otherwise. As a
reminder, what we ask you here is not the opposite of the previous
problem: the negation of “all even” is “at least one not even”.
Problem 4.5 – even.count(): Should return an integer that
represents how many of the numbers in the input list are even.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply