Write a Python function to perform a piece-wise linear approximation for the standard normal cumulative distribution function between 2 given points (as the lower and upper bounds) using the theoretical standard normal distribution given below.
As inputs, the function will take in the lower and upper bounds of the distribution as well as the number of pieces.
You can find an illustration of a piecewise linear approximation here. It might be useful to think of the area under the curve as rectangles and triangles.
Please note that scipy.stats.norm and np.piecewise are banned, and the only module you may use is numpy (obviously anything in numpy other than the piecewise function). That is, your code must not contain the string "scipy" or "np.piecewise". However, you are allowed to use the np.linspace function.
CLARIFICATION: You do NOT need to check the validity of the function inputs.
import numpy as np
lower_bound = float(input('Waiting for input: ')) # example: -1.96
upper_bound = float(input('Waiting for input: ')) # example: 1.96
num_pieces = int(input('Waiting for input: ')) # example: 100
def cdf_piecewise_approximation(lower_bound, upper_bound, num_pieces):
### ADD YOUR CODE BELOW
### ADD YOUR CODE ABOVE
return area
print(f"The approximation with this many pieces for P(lower_bound < x <= upper_bound) = {cdf_piecewise_approximation(lower_bound, upper_bound, num_pieces):.5f}")