So I'm working on an integral calculator right now, and it works fairly well, although as soon as defining y as x**2+x*2+2 it stops working. What prompts my program to work with y = x**2+2 but not with y = x**2+x*2+2?
import math as math
x0 = 0
x1 = 0
def func(y, x):
return eval(y)
def func2(z, x):
return eval(z)
def func3(c, d):
a = 0.0
for i in range(1, n+1):
x0 = a + (i-1) * dx
Ai = dx * (c + d)/ 2.
a = a + Ai
return a
y = str(raw_input("Function 1: "))
z = str(raw_input("Function 2: "))
a = float(input("Left boundary: "))
b = float(input("Right boundary: "))
dx = float(input("Trapezoid width: "))
n = int((b - a) / dx)
Area2 = func3(func(y, x0), func(y, x1))
Area3 = func3(func2(z, x0), func2(z, x1))
Area4 = Area2 - Area3
if Area4 < 0:
Area4 = Area3 - Area2
print "Area = ", Area4