Respuesta :
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.
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
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