Piecewise function & Math Functions

This problem requires the following calculation piecewise function f (x) values ​​(x is an arbitrary real number from a keyboard input):

O & piecewise .jpg

Input formats:

Directly into a real number x

Output formats:

In a row by "f (x) = result" output format, wherein x and result are three decimal places.

Sample input:

3.14
 

Sample output:

f(3.140)=0.865
import math
x = float(input())
a= math.fabs(x)
if  a < 1:
    b=math.sqrt(2-2*x)
    print('f({:.3f})={:.3f}'.format(x,b))
elif x >= 1:
    d=2.5+(x+math.log(100))
    b=(math.cos(x)+math.pow(x,2))/d
    print('f({:.3f})={:.3f}'.format(x, b))
else:
    b=math.exp(x)
    print('f({:.3f})={:.3f}'.format(x, b))

  

Guess you like

Origin www.cnblogs.com/SkystarX/p/12334040.html