Alex Rivera | Logout

Find the division remainder of a number

Asked 2011-04-07T16:44:16.820
236

How could I go about finding the division remainder of a number in Python?

For example:
If the number is 26 and divided number is 7, then the division remainder is 5.
(since 7+7+7=21 and 26-21=5.)


For simple divisibility testing, see How do you check whether a number is divisible by another number?.

Edit
Report

1 Answer

4

Modulo would be the correct answer, but if you're doing it manually this should work.

num = input("Enter a number: ")
div = input("Enter a divisor: ")

while num >= div:
    num -= div
print num
answered 2011-04-07T17:25:28.043

Your Answer