Question

Module SeqServices Uses None Syntax Exported Constants None Exported Access Programs Out Exceptions Routine name In is Ascending isIn Bounds interpLin interpQuad index X: R XRRR Semantics State Variables None State Invariant None
media%2F80b%2F80b2da7c-ce78-4c96-868d-c4
Write a library module that provides services for processing sequences. It should consist of a python code file named SeqServices.py. The specification for this module is given in the two pictures.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

def isAscending(X):
for i in range(len(X)-1):#loop till n-1 where n is len(X)
if X[i]>X[i+1]:#if a pair found out of order, return false
return False
return True#if no pair found out of order, return true
def isInBounds(X,x):
return x>=X[0] and x<=X[-1]#return true if x>=first element and x<= last element
def interpLin(x1,y1,x2,y2,x):
out = (float)(y2-y1)/(x2-x1)
out = out*(x-x1) + y1
return out#return value of out calculated using the formula
def interpQuad(x0,y0,x1,y1,x2,y2,x):
out = (float)(y2-y0)/(x2-x0)
out = out*(x-x1) + y1
out += (x-x1)*(x-x1)*(y2-2*y1+y0)/(2*(x2-x1)*(x2-x1))
return out#return value of out calculated using the formula
def index(X,x):
for i in range(len(X)-1):
if x >= X[i] and x<X[i+1]:#finds the i for which X[i]<=x<X[i+1]
return i#return i
return len(X)-1#else return last index of X

Refer to image below for better understanding and proper indentation.

File Edit Selection Find View Goto Tools Project Preferences Help 1 def isAscending(X): range(len(X) 1):#loop till found len(

Sample output:

>>>isAscending (X) False >>>isAscending (X) True >>isInBounds (X, 3) True >>isInBounds (X, 4) True >>> interpLin (1,2,2,4,3)

The comments in the code are only for you understanding. You can remove them if you want.

Please give this solution a thumbs up if you find it helpful. Kindly let me know in the comments if you have any doubts or issues in the solution. I would be happy to help you.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Write a library module that provides services for processing sequences. It should consist of a python...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data...

    Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT