Each element in its input list is at most as big as the one before it
Question:-
Define a Python function "descending(l)" that returns True if each element in its input list is at most as big as the one before it
For instance:
>>> descending([])True
>>> descending([4,4,3])True
>>> descending([19,17,18,7])False
Answer:-
def descending(l):
a=True
if l==[]:
return True
for x in range(0,len(l)-1):
if l[x]<l[x+1]:
a=False
break
return a
Define a Python function "descending(l)" that returns True if each element in its input list is at most as big as the one before it
For instance:
>>> descending([])True
>>> descending([4,4,3])True
>>> descending([19,17,18,7])False
Answer:-
def descending(l):
a=True
if l==[]:
return True
for x in range(0,len(l)-1):
if l[x]<l[x+1]:
a=False
break
return a
Comments
Post a Comment