Hide

Problem C
Within Range

If you are doing this problem outside of a class, or your instructor has not given you code to use as a starting point, skip ahead to the Input/Output sections for a concise description of the input/output requirements of this problem.

CS 121 students: To solve this problem, use file withinrange.py from your CS 121 repository as a starting point. It will handle the input/output, and all you will need to do is add code in the places indicated in the file.

More specifically, you are provided with a within_bounds(x, lb, ub) function which returns True if $lb \leqslant x \leqslant ub$, and False otherwise. You must implement a function called within_range that returns True if $x$ is within a given range ($r$) of $c$, and False otherwise. Your implementation of within_range must involve a call to within_bounds(x, lb, ub).

If you are using withinrange.py as a starting point, you can ignore the rest of the Input/Output sections below. Just submit your modified withinrange.py once you have written your solution.

Input

The input is three integers: $x$, $c$, and $r$, each separated by a single space. The bounds of the numbers are: $-100 \leqslant x,c \leqslant 100$, and $0 \leqslant r \leqslant 100$

Output

If $x$ is within a given range ($r$) of $c$, print True. Otherwise, print True

Sample Input 1 Sample Output 1
5 8 2
False
Sample Input 2 Sample Output 2
5 8 4
True
Sample Input 3 Sample Output 3
98 75 100
True

Please log in to submit a solution to this problem

Log in