Here is how you can incorporate the conditions into the function:
def f(x):
if x <= 15:
return x * 2 + 10
if x <= 35:
return 3 * x ** 2
return 2 * x**3 - 5
When calling the function:
>>> f(31.039)
2890.2585630000003
>>> f(42.103)
149263.82765345403
>>>
For the display_f
:
def f(x):
if x <= 15:
return x * 2 + 10
if x <= 35:
return 3 * x ** 2
return 2 * x**3 - 5
number = float(input("Enter a real number: "))
num = '{:.3f}'.format(number)
display_f = f"f({num}) = {'{:.3f}'.format(round(f(number), 3))}"
print(display_f)
Output:
Enter a real number: 51.73
f(51.730) = 276853.225
0
solved real-valued function in python [closed]