Getting started with lists
A function which defines a list and we will get an output list
A function that takes the input of a list of integers and the output is True if the absolute difference between adjacent numbers is strictly decreasing.
9-2=7; |2-5|=3; 5-4=1
Hence the output must be True.
Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!
def contracting(l): hv=0 vc=0 for i in range(1,len(l)-1): if(abs(l[i]-l[i-1])>abs(l[i+1]-l[i])): hv=hv+1 else: vc=vc+1 if(vc==0): return(True) else: return(False) a=input("Enter a list of integers:") arr = list(map(int, a.split())) print(contracting(arr))