How to check if a number is multiple of 10 in Python
In this tutorial, we are going to learn about how to check if a given number is multiple of 10 or not in Python.
Consider, we have a following number:
a = 100To find if a above number 100 is a multiple of 10 the number should be divided by 10 and the remainder is 0.
Using % Modulo operator
To check if a number is multiple of 10 or not, we can use the % modulo operator in Python.
The modulo % operator returns the remainder of two numbers 100 % 10, so if we get a remainder 0 then the given number is a multiple of 10.
Here is an example:
a = 100
if a % 10 == 0 :
print("a is multiple of 10")
else:
print("a is not a muliple of 10")Output:
"a is multiple of 10"In the above code we have added a % 10 == 0 in if condition, so 100 is divided by 10 and returns the remainder 0 then it prints the output “a is multiple of 10”.
Example 2 :
b = 300
if b % 10 == 0 :
print("b is multiple of 10")
else:
print("b is not a muliple of 10")Output:
"b is multiple of 10"Checking if a number is not a multiple of 10
To check if a number is not a multiple of 10, we can use the modulo operator % but the remainder of first number by second number is not equal to 0.
Here is an example:
if (23 % 10 != 0):
print ("23 is not a multiple of 10")In the above code, 23 is divided by 10 and returns the remainder 3. So the given number is not a multiple of 10.


