[Solved] how to evaluate an equation with python [closed]


You can loop over values like this:

for x in [-60.0, -45.0, -30.0]:  # etc; notice how the .0 specifies a float
    print('D({0}) = {1}'.format(x, A*math.cos(x)**2+B*math.sin(x)+C))

If you intend for the output to be machine-readable, maybe change the format string to something like '{0},{1}' for simple CSV output.

Just print will print nothing (well, or actually an empty line).

In Python, cos is the function which calculates things; you cannot exponentiate this object, but you can call it and exponentiate its result; thus cos(x)**2 rather than cos**2(x) (which makes as little sense as doing, say, import**2 and then trying to use the result as a function which you pass x to).

11

solved how to evaluate an equation with python [closed]