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
If you want to avoid modulo, you can also use a combination of the four basic operations :)
26 - (26 // 7 * 7) = 5
you are looking for the modulo operator:
a % b
for example:
26 % 7
Of course, maybe they wanted you to implement it yourself, which wouldn't be too difficult either.
If you want to get quotient and remainder in one line of code (more general usecase), use:
quotient, remainder = divmod(dividend, divisor)
#or
divmod(26, 7)
You can find remainder using modulo operator Example
a=14
b=10
print(a%b)
It will print 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
26 % 7 (you will get remainder)
26 / 7 (you will get divisor can be float value )
26 // 7 (you will get divisor only integer value) )