Ask Question
28 March, 05:36

Associate true with the variable is_ascending if the list numbers is in ascending order (that is, if each element of the list is greater than or equal to the previous element in the list). otherwise, associate false with is_ascending

+5
Answers (2)
  1. 28 March, 09:00
    0
    The "is_ascending" variable allows for the programmer to denote if the list in question is in ascending order. If the list is in ascending order, then the variable "is_ascending" is considered true, and marked with variable as such. If the list is in descending order, in no discernible order, etc., the is_ascending variable does not apply, and is therefore false in reference to that list.
  2. 28 March, 09:04
    0
    Is_ascending = True

    p = None

    for n in numbers:

    ... if p is not None and n < p:

    ... is_ascending = False

    ... break

    ... p = n

    This would also work

    is_ascending = True if numbers = = sorted (numbers) else False

    In a real world scenario I would probably do this.

    def issorted (seq):

    ... if not seq: return True

    ... iseq = iter (seq)

    ... prev = next (iseq)

    ... for x in iseq:

    ... if x < prev:

    ... return False

    ... return True

    The answer the is_ascending is False
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Associate true with the variable is_ascending if the list numbers is in ascending order (that is, if each element of the list is greater ...” in 📘 History if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers