Cooper Koenig Cooper Koenig - 1 month ago 7
Python Question

Python adding a number to another number to get a number divisible by 10

for example k = (93 + k) % 10
return k
Is there an algorithm that will get me to return 7?

Answer

What you want is simply a=(-k % 10) .

The explanation is basic modulo arthmetic : (a+k) %10= a%10 + k%10 = -k %10 + k%10 = 0 %10

Comments