
Eli J. answered 02/05/20
Expert Math Tutor: All Ages and Courses
Let's tackle this one thing at a time and then combine them all at the end. It sounds like neither the choice of the function nor the choice of the point are part of the inputs, i.e., the function/point gets chosen before writing the program, and is not an option for the user.
- Plot a graph of the function:
Use a graph plotting library if you don't want to reinvent the wheel here. A popular one is pylab. You probably also want to import numpy, both to have more freedom with what functions you can introduce and to make it easier to generate pairs of x/y values to plot. I'm going to choose as my function y = sin(x), and x = 1 as my point
No interactivity yet, but we're getting there.
- The user can choose a nearby point
We're going to need an input here. We should really make sure the input is a valid one, and not too far from 1 (or worse, not a real number at all). Since I don't know exactly how much you've learned about try/except blocks or exception handling yet, I'm going to just do the bare minimum here and just get an input:
Putting the rest in is not too much work if you remember your algebra formulas:
The next step, if you want to improve this, would be to handle bad inputs the user might enter.