Restrict the Range X85359


Statement
 

pdf   zip   main.py

Write a function restrict_rangerestrict\_range that receives a function operating on floats ff, a lower bound lblb and an upper bound ubub. Then, restrict_rangerestrict\_range returns a new function that operates exactly as ff when f(x)f(x) falls within the closed interval [lb,ub][lb, ub]. Instead of outputs outside that interval, the function produced returns $float("-inf")$.

Sample session
>>> f = restrict_range(lambda x: x * x * x, 1, 1000)
>>> f(1)
1.0
>>> f(-5)
-inf
>>> f(5)
125.0
>>> f(10)
1000.0
>>> f(11)
-inf
Information
Author
Jordi Delgado and José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python