CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day03/piecewise.py
Views: 729
1
"""
2
分段函数求值
3
3x - 5 (x > 1)
4
f(x) = x + 2 (-1 <= x <= 1)
5
5x + 3 (x < -1)
6
7
Version: 0.1
8
Author: 骆昊
9
Date: 2018-02-28
10
"""
11
12
x = float(input('x = '))
13
if x > 1:
14
y = 3 * x - 5
15
elif x >= -1:
16
y = x + 2
17
else:
18
y = 5 * x + 3
19
print('f(%.2f) = %.2f' % (x, y))
20
21