Python Code: Problem – Order testing [3 ×5 points] All functions you are asked to define for this problem should accept

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 – Order testing [3 ×5 points] All functions you are asked to define for this problem should accept

Post by answerhappygod »

Python Code:
Problem – Order testing [3 ×5 points] All functions you are
asked to define for this problem should accept the same kind of
arguments: a list of values that can be compared against each
other. All functions return a boolean value, but based on different
criteria (as stated below). Finally, none of the functions should
modify their input list in any way.
Remark: You may use the all() built-in function, if you wish. In
general, you can use any built-in functions or standard library
functions (no external dependencies, of course), unless explicitly
mentioned otherwise for a particular problem.
Problem 7.1 – listlib.is ascending() Returns True if the
elements of the input list are in non- decreasing order, and False
otherwise.
Problem 7.2 – listlib.is descending() Returns True if the
elements of the input list are in non- increasing order, and False
otherwise.
Problem 7.3 – listlib.is sorted() Returns True if the elements
of the input list are in either non- decreasing or non-increasing
order, and False otherwise.
Hint [1]: The formal definition of non-decreasing should tell
you how to implement is_ascending: a sequence a0,a1,...,aN−1 is
non-decreasing if and only if ai−1 ≤ ai for all 1 ≤ i < N. In
case the “for all” phrasing isn’t clear, another way to state the
definition is that (a0 ≤a1) and (a1 ≤a2) and ··· and (aN−2 ≤ aN−1)
should be true. Once you’ve implemented is_ascending, it should be
very easy to also do is_descending.
Hint [2]: Just in case: the definition of sorted (i.e., either
non-decreasing or non-increasing) is not that (ai−1 ≤ ai) or (ai−1
≥ ai) should be true for all 1 ≤ i < N (actually, this statement
is a logical tautology, i.e., it is always trivially true). Don’t
over-complicate; if you use is_ascending and is_descending, then
the implementation of is_sorted should be fairly trivial.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply