Oct-08-2023, 04:20 PM
Write a program in python that, based on the entered argument value,
calculates the value of a function specified as a graph. Sorry for my bad English. Function for writing a program on a photo.
Description of the algorithm:
1. Enter the value of argument x and convert it to float.
2. Determine to which interval from the domain of definition of the function it
belongs, and calculate the value of the function y from the corresponding
formula.
3. Print the value of x and y.
Description of input and output data:
Input data comes from the keyboard, and output data is output to
monitor for viewing. The input and output data are of type float.
Program listing (option 1):
for all conditional statements, including those following
calculated. So, for example, if x is -3, then the second one will be executed
operator, but in all subsequent operators the comparison operation will be
carried out. The number of checks can be reduced by writing a program with
using nested conditional statements.
Program listing (option 2):
Enter the argument value: -6
X= -6.00 Y= 1
Enter the argument value: -3.33
X= -3.33 Y= -0.00
Enter argument value: 6
X= 6.00 Y= 4.00
calculates the value of a function specified as a graph. Sorry for my bad English. Function for writing a program on a photo.
Description of the algorithm:
1. Enter the value of argument x and convert it to float.
2. Determine to which interval from the domain of definition of the function it
belongs, and calculate the value of the function y from the corresponding
formula.
3. Print the value of x and y.
Description of input and output data:
Input data comes from the keyboard, and output data is output to
monitor for viewing. The input and output data are of type float.
Program listing (option 1):
from math import * # now you can do this: # print(sin(pi/4)) x = float(input('Enter value x=')) if x < -5: y = 1 if x >=-5 and x<0: y = -(3/5)*x-2 if x >= 0 and x<2: y = -sqrt(4-x**2) if x >= 2 and x<4: y = x-2 if x >= 4 and x<8: y = 2+sqrt(4-(x-6)**2) if x >= 8: y = 2 print("X={0:.2f} Y={1:.2f}".format(x, y))It should be noted that in this recording of the algorithm the check is performed
for all conditional statements, including those following
calculated. So, for example, if x is -3, then the second one will be executed
operator, but in all subsequent operators the comparison operation will be
carried out. The number of checks can be reduced by writing a program with
using nested conditional statements.
Program listing (option 2):
from math import * # now you can do this: # print sin(pi/4) x = float(input('Enter value x=')) if x < -5: y = 1 elif x >=-5 and x<0: y = -(3/5)*x-2 elif x >= 0 and x<2: y = -sqrt(4-x**2) elif x >= 2 and x<4: y=x-2 elif x >= 4 and x<8: y = 2+sqrt(4-(x-6)**2) else: y = 2 print("X={0:.2f} Y={1:.2f}".format(x, y))Result of the program:
Enter the argument value: -6
X= -6.00 Y= 1
Enter the argument value: -3.33
X= -3.33 Y= -0.00
Enter argument value: 6
X= 6.00 Y= 4.00