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

Sacred Thought

28 April 2024 Today I am going to explain verse 31 - 38 chapter two for you all. There is no opportunity better than a righteous war (सत्य औ...