← Back to challenges

Check if Number is within a Given Range

PythonHardnumberslanguage_fundamentalsobjectsvalidation

Instructions

Given a number and a dictionary with min and max properties, return True if the number lies within the given range (inclusive).

Examples

is_in_range(4, { "min": 0, "max": 5 }) ➞ True

is_in_range(4, { "min": 4, "max": 5 }) ➞ True

is_in_range(4, { "min": 6, "max": 10 }) ➞ False

is_in_range(5, { "min": 5, "max": 5 }) ➞ True

Notes

  • Numbers can be positive or negative, and they may not be integers.
  • You can assume min <= max is always true.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Minimum Removals to Make Sum Even