0

I have a small task within my script that I need to handle and i'm really not sure how I should go about doing it.

The function takes an integer and I need to find upper and lower bounds that the integer lies between.

The upper and lower bounds will always be 5 numbers apart. For example, if the inputted integer is 4 then the lower bound would be 0 and the upper bound would be 5.

Another example would be if the inputted integer is 26, the lower bound would be 25 and the upper bound would be 30.

Could anyone give me some starting information as to what would be a good way to go about tackling this? I'm thinking that I could just find the lower bound and then add 5 to it in order to find the upper bound? I'm just not entirely certain what would be the most efficient way to find one bound.

5
  • Why 0 and 5 and not 1 and 6 or 2 and 7 or ... Commented Jan 4, 2017 at 15:10
  • The question seems pretty specific and clear to me. I'd be interested to know why someone voted to close for being off-topic; this question isn't requesting debugging help, it's an algoritm question. Commented Jan 4, 2017 at 15:11
  • @jonrsharpe It's essentially a grid of squares. The lowest point on the grid is 0,0. Each box has a length of 5 and a width of 5. If a point lies on a line it won't matter because I have other inputted integers to tell me exactly where on the grid it lies. Commented Jan 4, 2017 at 15:12
  • What should happen if the input is a multiple of 5? For instance, if you have 25, do you want [20, 25] or [25, 30]? Commented Jan 4, 2017 at 15:17
  • @VincentSavard I have other inputted integers that will determine which square on the grid that will tell me exactly which bounds to use. Commented Jan 4, 2017 at 15:18

1 Answer 1

5
number = input() lowerBound = number - (number % 5) upperBound = lowerBound + 5 
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I needed! Thank you very much. I really didn't expect it to be this simple and straightforward. Thank you very much.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.