更新
This commit is contained in:
21
Python-100-Days/Day01-15/Day03/piecewise.py
Normal file
21
Python-100-Days/Day01-15/Day03/piecewise.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
|
||||
分段函数求值
|
||||
3x - 5 (x > 1)
|
||||
f(x) = x + 2 (-1 <= x <= 1)
|
||||
5x + 3 (x < -1)
|
||||
|
||||
Version: 0.1
|
||||
Author: 骆昊
|
||||
Date: 2018-02-28
|
||||
|
||||
"""
|
||||
|
||||
x = float(input('x = '))
|
||||
if x > 1:
|
||||
y = 3 * x - 5
|
||||
elif x >= -1:
|
||||
y = x + 2
|
||||
else:
|
||||
y = 5 * x + 3
|
||||
print('f(%.2f) = %.2f' % (x, y))
|
||||
Reference in New Issue
Block a user