Python 3 Script to Check Whether an Array is Monotonic or Not Full Tutorial For Beginners

Python 3 Script to Check Whether an Array is Monotonic or Not Full Tutorial For Beginners

 

Welcome folks today in this post we will be checking whether an array is monotonic or not in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

# Python3 program to find sum in Nth group 
  
# Check if given array is Monotonic 
def isMonotonic(A): 
  
    return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or
            all(A[i] >= A[i + 1] for i in range(len(A) - 1))) 
  
# Driver program 
A = [6, 5, 4, 4] 
  
# Print required result 
print(isMonotonic(A)) 
  
# This code is written by

 

See also  Python 3 Tkinter Drawing Rectangle With Rounded Corners on Canvas Window GUI Desktop App Full Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py

 

Leave a Reply