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

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...