Sunday, February 25, 2018

Python program :That returns True if each element in its input list is at least as big as the one before it.

Define a Python function ascending(l) that returns True if each element in its input list is at least as big as the one before it.

Here are some examples to show how your function should work.


>>> ascending([])
True
>>> ascending([3,3,4])
True
>>> ascending([7,18,17,19])
False 
 
def ascending(l):
  n=len(l)
  status=False
  if n<=1:
    return(True)
  for i in range(0,n-1):
    if(l[i]<=l[i+1]):
      status=True
    else:
      status=False
      break
  return(status)
      
      Thanks
Happy Programming ! 
 

No comments:

Post a Comment

Query for finding high dividend paying stocks

 Post the following query in Screen.in, to get list of high dividend yield stocks: Dividend yield > 6 AND Dividend last year > 1000 AN...