Answer to Question #303657 in Python for JJJ

Question #303657

Write a function called propagateUncertainty() that accepts as input two variables in the format x = [x_best,dx] and y = [y_best,dy]. Have your function calculate the sum q = x + y as well as the corresponding max uncertainty dq = dx + dy and return an answer in the same format of the inputs (i.e., q = [q_best,dq]).


If either of the inputs does not have two entries, your function should return the string "Fail" and print the statement "Array length must be equal to two with the format x = [x_best,dx]."

If either of the inputs contains non-numeric entries (i.e., type(entry) is not equal to "int" or "float"), your function should return the string "Fail" and print the statement "Non-numeric entry!"


1
Expert's answer
2022-02-28T01:06:43-0500
def propagateUncertainty(x, y):
  if len(x) != 2 or len(y) != 2:
    raise Error('Array length must be equal to two with the format x = [x_best,dx]')
  if x[0] is not float or \
     x[1] is not float or \
     y[0] is not float or \ 
     y[1] is not float:
    raise Error('Non-numeric entry!')
  return [x[0]+y[0], x[1]+y[1]]

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS