Ask Question
16 June, 19:47

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

+4
Answers (2)
  1. 16 June, 22:30
    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. 16 June, 23:19
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers