编程计算分段函数 输入x的值,输出y的值

img

import math

x=eval(input())
if x>5:
    print('y=',math.sin(x)+math.sqrt(math.pow(x,2)+1))
elif 0<x and x<=5:
    print('y=',math.pow(math.e,2)+math.log(5,x)+math.pow(x,1/5))
elif x<=0:
    print('y=', math.cos(x)-math.pow(x,3)+3*x)

有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力

import math
import numpy as np
def func(x):
        return np.piecewise(x, [x>5, x<=5 and x>0, x<=0], \
        [lambda x: math.sin(x)+math.sqrt(math.pow(x,2)+1),\
        lambda x: math.pow(math.e,2)+math.log(5,x)+math.pow(x,1/5),\
        lambda x: math.cos(x)-math.pow(x,3)+3*x])
y = func(x)

if x>5:
y=(...)
elif x>0:
y=(...)
else
y=(...)