Оригинальный Код.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double f, xstart, xend, dx, eps=0.00000000001;
cout <<“Enter xstart: ”; cin>>xstart;
cout <<“Enter xend: ”; cin>>xend;
cout <<“Enter dx: ”; cin>>dx;
cout <<“ TABL 1\n”<<“ x”<<“ ”<<“f(x)”<<endl;
for (double i=xstart; i<=xend; i+=dx)
{
if (i>=-3 && i<=-2) f=-i-2;
if (i>-2 && i<-1) f=sqrt(1-(i+1)*(i+1));
if (i>=-1 && i<=1) f=1;
if (i>1 && i<2) f=-2*i+3;
if (i>=2 && i <=5) f=-1;
if ((i>-2-eps&&i<-2+eps)||(i>1.5-eps&&i<1.5+eps)) cout<<setw(6)<<i<<“ ”<<0<<endl;
else if (i>-eps&&i<eps) cout<<setw(6)<<0<<“ ”<<f<<endl;
else cout<<setw(6)<<i<<“ ”<<f<<endl;
}
system(“pause”);
return 0;
}
Что у меня вышло для Python-
import cmath
print (“Введите x, y”)
xn = float (input(“xn = ”))
xk = float (input(“xk = ”))
dx = float (input(“dx = ”))
f = float
i = float
eps = float
eps = 0.000000000001
input(“ TABL 1\n”“ x”“ ”“f(x)”)
for i=xn in i<=xk in i+=dx
if i>=-3 and i<=-2:
f=-i-2
elif i>-2 and i<-1:
f=cmath.sqrt(1-(i+1)*(i+1))
elif i>=-1 and i<=1:
f=1
elif i>1 and i<2:
f=-2*i+3
elif i>=2 and i<=5:
f=-1
if ((i>-2-eps and i<-2+eps) or (i>1.5-eps and i<1.5+eps)):
print (“%5d%7d” % (“ ”,f,))
elif (i>-eps and i<eps):
print (“%5d%7d” % (,0,“ ”,f,))
else:
print (“%5d%7d” % (,i,“ ”))
input('Press ENTER to exit')
Не знаю как сделать, чтобы работало.