avatar Bite 289. Round to next number

Write a function that accepts a number and a multiple, then rounds the number towards the next multiple.

Examples:  

Number Multiple Output
0 5 0
2 5 5
5 5 5
42 5 45
-6 -10 -10
-6 -10 -10

---

Imagine this on a number line.  

* Number: 0 Multiple: 5  

-3 -2 -1 0 1 2 3 4 5
      0          
      0          

 

Since zero is a multiple of five the answer is 0.  

---

* Number: 2 Multiple: 5  

-5 -4 -3 -2 -1 0 1 2 3 4 5
              2      
              =>     5

 

The next multiple of five from two is 5.

---

* Number: -6 Multiple: -10  

-10 -9 -8 -7 -6 -5 -4 -3 -2 -1
        -6          
-10       <=          

 

The next multiple of negative 10 from negative six is -10.  

Login and get coding
go back Beginner level
Bitecoin 2X

150 out of 152 users completed this Bite.
Will you be Pythonista #151 to crack this Bite?
Resolution time: ~31 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 3.2 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help