The Story So Far
Your method for estimating the area under a curve is a smash hit, but it still has some naysayers. Fortunately, you know the best way to convince other academics of your findings: an overwhelming number of cherry-picked examples. Computer-assisted proofs are all the rage ever since some Illinoisians colored a map!
You look back at your favorite function - $x^3 - 3x^2 + 2x + 1$ - and your favorite interval - the squiggly one between $0$ and $2$ - and you want to create a function that can show people that - no matter how many pieces you subdivide it, your method gets the right answer.
To get started, we will first define a function example_quadratic
which conforms to the following docstring specification:
"""
Computes $x^3-3x^2+2x+1$ at a value x.
Parameters
----------
x : float
The value to compute the function at.
Returns
-------
y : The value of the given function at $x$.
Examples
--------
>>> example_quadratic(1)
1.0
>>> example_quadratic(1.5)
0.625
"""
Try it out on a few points, and check by hand whether you are getting the correct value.
Upload a
.py
file to Brightspace which contains the described function, and - outside of the function - usesinput
to get a value from the user, then prints the result.