Number is divisible | Challenge

PythonPythonBeginner
Practice Now

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python/BasicConceptsGroup -.-> python/comments("`Comments`") python/BasicConceptsGroup -.-> python/booleans("`Booleans`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/FunctionsGroup -.-> python/function_definition("`Function Definition`") subgraph Lab Skills python/comments -.-> lab-13136{{"`Number is divisible | Challenge`"}} python/booleans -.-> lab-13136{{"`Number is divisible | Challenge`"}} python/tuples -.-> lab-13136{{"`Number is divisible | Challenge`"}} python/function_definition -.-> lab-13136{{"`Number is divisible | Challenge`"}} end

Number is divisible

Problem

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.

Example

is_divisible(6, 3) ## True
is_divisible(7, 2) ## False
is_divisible(10, 5) ## 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.

Other Python Tutorials you may like