Python Program to Check for Divisibility of a Number

  • In this Python example will check the given two numbers are divisable or not
  • Take two numbers numerator and denominator from user inputs
  • converts entered two numbers into integer by int() method and assign to variable x,y
  • converts entered two numbers into integer by int() method and assign to variable x as numerator,y as denominator
  • now check the module of x%y equals to zero, then numbers are divisable
  • if x module of y not equals to zero then numbers are not divisable
x = int(input("Insert the numerator: "))
y = int(input("Insert the denominator: "))

if x % y == 0:
    print(x, " is divisible by ", y)
else:
    print("No! ", x, " is not divisible by ", y)

 

Output:

Insert the numerator: 24
Insert the denominator: 4
24  is divisible by  4

 

 

Insert the numerator: 25
Insert the denominator: 3
No!  25  is not divisible by  3

 

Subscribe For Daily Updates