# How you can Spherical as much as the Subsequent A number of of 5 in Python

0
10

## The problem#

Given an integer as enter, are you able to spherical it to the subsequent (which means, “larger”) a number of of 5?

Examples:

``````enter:    output:
0    ->   0
2    ->   5
3    ->   5
12   ->   15
21   ->   25
30   ->   30
-2   ->   0
-5   ->   -5
and so forth.
``````

Enter could also be any constructive or damaging integer (together with 0).

You’ll be able to assume that every one inputs are legitimate integers.

## The answer in Python code#

Possibility 1:

``````def round_to_next5(n):
return n + (5 - n) % 5
``````

Possibility 2:

``````def round_to_next5(n):
whereas npercent5!=0:
n+=1
return n
``````

Possibility 3:

``````import math
def round_to_next5(n):
return math.ceil(n/5.0) * 5
``````

## Check circumstances to validate our resolution#

``````inp = 0
out = round_to_next5(inp)
check.assert_equals(out, 0, "Enter: {}".format(inp))

inp = 1
out = round_to_next5(inp)
check.assert_equals(out, 5, "Enter: {}".format(inp))

inp = -1
out = round_to_next5(inp)
check.assert_equals(out, 0, "Enter: {}".format(inp))

inp = 5
out = round_to_next5(inp)
check.assert_equals(out, 5, "Enter: {}".format(inp))

inp = 7
out = round_to_next5(inp)
check.assert_equals(out, 10, "Enter: {}".format(inp))

inp = 20
out = round_to_next5(inp)
check.assert_equals(out, 20, "Enter: {}".format(inp))

inp = 39
out = round_to_next5(inp)
check.assert_equals(out, 40, "Enter: {}".format(inp))
``````