# 编写程序,实现分段函数的计算。
def piecemise_function(x):
if x < 0:
return 0
elif 0 <= x < 5:
return x
elif 5 <= x < 10:
return 3 * x - 5
elif 10 <= x < 20:
return x - 2
else: # x >= 20
return 0
while True:
x = int(input("请输入x的值:"))
y = piecemise_function(x)
# 打印结果
print(f"X = {x}: Y = {y}")