What is the difference between / and % in the following context? Why isn't / working

The question is: Write a function named remainder() that has two parameters named num1 and num2. The function should return the remainder of twice num1 divided by half of nym2.

I wrote:
def remainder(num1, num2):
return (num1*2)/(num2/2)

It wasn’t working so I switch the / to % and it worked, my question is why isn’t the / working in this context?

Edit: I think I found the answer, it’s because it’s a Modulo and % is giving the rest of the devision.


Correct. Modulo is very useful, so it’s good to keep it in mind.

1 Like

The / symbol is strictly for division, so what that code was doing was actually just dividing. The % symbol (also called modulo) is used for finding what the remainder would be if you divided 2 digits. That’s why % worked and not /.
Hope this helped!