+ 1
Find out if the number is divided by another
I created a variable that asks for a number. How to find out if this number is divisible by 10, and send "The number is divisible by 10"?
6 Antworten
+ 3
use % ("mod" operator), it returns remainder after division.
if num is divisible by 10, remainder after division will be 0.
if num%10 == 0:
#divisible
else :
#not divisible
+ 5
def is_divisible_by(your_number):
return your_number % 10 == 0
+ 2
Code learner Oh. I tried to do so, and an error appeared, apparently due to gaps. Thank))
+ 1
A different way to everyone else :)
if x[-1] == '0':
print('It is divisible by 10.')
It checks if the last digit is 0, which is what is true with all numbers divisible by 10.
+ 1
Dan Rhamba, I like yours :)
+ 1
if number%10 ==0:
print("the number is divisble")
else:
print("the number is not divisible")