import math
x = float(input('Введите аргумент Х точки: '))
if -3 <= x < -1:
y = -x + 1
elif -1 <= x < 1:
y = 0
elif 1 <= x < 5:
y = math.sqrt(4 - (x-3)*(x-3))
elif 5 <= x < 7:
y = -(x/2)+2.5
else:
print('Х вне допустимого диапазона')
input()
exit()
print('Точка с координатами %2.2f ; %2.2f'%(x, y))
А это так, для интереса и наглядности:
import turtle, math
def line(x1,y1,x2,y2):
turtle.pu()
turtle.goto(x1,y1)
turtle.pd()
turtle.goto(x2,y2)
turtle.pu()
turtle.title('График функции')
turtle.setup(800,400)
turtle.setworldcoordinates(-4,-2,8,4)
turtle.hideturtle()
line(-4,0,8,0)
line(0,-2,0,4)
for x in range(-3,8):
line(x,-0.1, x, 0.1)
for y in range(-1, 4):
line(-0.1,y,0.1,y)
turtle.pensize(2)
line(-3,2,-1,0)
line(-1,0,1,0)
turtle.pd()
x = 1
while x < 5:
turtle.goto(x, math.sqrt(4 - (x-3)*(x-3)))
x += 0.01
line(5,0,7,-1)
x = float(input('Введите аргумент Х точки: '))
turtle.pencolor('red')
if -3 <= x < -1:
y = -x + 1
elif -1 <= x < 1:
y = 0
elif 1 <= x < 5:
y = math.sqrt(4 - (x-3)*(x-3))
elif 5 <= x < 7:
y = -(x/2)+2.5
else:
print('Х вне допустимого диапазона')
input()
exit()
y1 = '%2.2f'%y
print('y = %2.2f'%y)
turtle.pu()
turtle.goto(x,y)
turtle.dot(7, 'red')
turtle.pensize(1)
turtle.pencolor('green')
line(x,y,0,y)
line(x,y,x,0)
turtle.goto(0.5,3.5)
turtle.write('Точка ('+str(x)+'; '+y1+')', font=('Arial',10))
turtle.exitonclick()
Поделитесь своими знаниями, ответьте на вопрос:
1) вводится последовательность из n целых чисел. взять корень из всех положительных чисел, найти их сумму и количество . 2) начав тренировки, спортсмен пробежал s км. каждый следующий день он увеличивал дневную норму на p% от нормы предыдущего дня. определить, через сколько дней спортсмен будет в день пробегать r км. написать на с++ и желательно сделать блок схемы, или хотя бы просто блок схемы
#include <cmath>
using namespace std;
void main()
{
int n,sum=0;
float y,k=0;
cin >> n;
int *mass = new int[n];
for (int i = 0;i < n;++i)
{
cin >> mass[i];
}
for (int i = 0;i < n;++i)
{
if (mass[i] >0 )
{
k++;
y=pow(mass[i],2);
cout<<y;
sum+=mas[i]
}
}
system("pause");
}
2)#include <iostream>
#include <cmath>
using namespace std;
void main()
{
int s,p,r,day=0;
cin >> s>>p>>r;
float km=s;
while(r>km)
{
km+=km*p/100;
day++;
}
cout << " km = " << km << " day = " << day << endl;
system ("pause");
}