# How can i calculate multiple of 10

im a Beginner in python and i don’t know how to Write a program that reads a number from the input and prints the next multiple of 10 that is greater than this number. For example, if the number 11 is read from the input, the number 20 should be printed. If the number 40 is read, the number 50 should be printed.

Please show the code you have written so far so that we have something to work from.
Cut-n-paste your code between so-called code-fences like this:





I assume that when you say “greater” it means strictly greater. For example, that for the input 10 the result should be 20. Maybe clarify if for the input 10 the output should be 10.

You know that the floor function \lfloor\cdot\rfloor satisfies (perhaps that’s you definition)

\lfloor y\rfloor \leq y<\lfloor y\rfloor

So, putting y=x and multiplying by 10

10\lfloor\frac{x}{10}\rfloor\leq x<10\lfloor x/10\rfloor +10

So, the smallest multiple of 10 larger than x is 10\lfloor x/10\rfloor +10.

Check in the documentation if the function math.floor gives the same result as \lfloor\cdot \rfloor and then you could do 10 * math.floor(x/10) + 10

Check which type of input you will get. Can x be any of the values of float? Maybe cover the cases x equal to the values float('inf'), float('-inf'), float('nan').

2 Likes

Some things to consider:

• user input is string, so conversion to int is required
• there is // (floor division) operator

For example:

>>> int('11') // 10
1
>>> (int('11') // 10 + 1) * 10
20
3 Likes

For an int calculation I would not be using math.floor
The modulus operator % and the integer divide // are, I think, the key to this.

As you say need to confirm if input of 10 is expected to be 20 or 10.

1 Like

thank you for help