Ask Question
30 November, 01:15

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

+2
Answers (2)
  1. 30 November, 01:24
    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. 30 November, 01:41
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers