Blog
Getting started with lists
- Akhila27
- October 10, 2020
- 9:37 pm
- No Comments
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.
For example:
a=[9,2,5,4]
9-2=7; |2-5|=3; 5-4=1
7>3>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))
4
1
vote
Rating
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments