Determine Number Divisibility in Python

Beginner

This tutorial is from open-source community. Access the source code

Introduction

In Python, we can use the modulo operator (%) to check if a number is divisible by another number. If the remainder is equal to 0, then the number is divisible. In this challenge, you will create a function that checks if a number is divisible by another number.

Number is divisible

Write a function is_divisible(dividend, divisor) that takes two integers as arguments and returns True if the dividend is divisible by the divisor, and False otherwise.

def is_divisible(dividend, divisor):
  return dividend % divisor == 0
is_divisible(6, 3) ## True

Summary

In this challenge, you learned how to check if a number is divisible by another number using the modulo operator. You created a function that takes two integers as arguments and returns True if the dividend is divisible by the divisor, and False otherwise.