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!"
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]]
Comments
Leave a comment