Member-only story

Finding the Remainder in Python

A Beginner’s Guide to the Modulo Operator and Functions

Max N
3 min readJun 15, 2023
Photo by Victoria Strukovskaya on Unsplash

Introduction

Today, we’ll be exploring a Python programming problem called “Return the Remainder from Two Numbers.” This problem is an excellent opportunity to practice your skills and learn some fundamental concepts in Python, such as the modulo operator.

By the end of this article, you’ll have a better understanding of how to write a simple function to find the remainder of a division operation.

Problem Statement

The problem we’re trying to solve is as follows:

There is a single operator in Python, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value.

Here are some examples of how the function should work:

  • remainder(1, 3) ➞ 1
  • remainder(3, 4) ➞ 3
  • remainder5, 5) ➞ 0
  • remainder(7, 2) ➞ 1

Note: The tests only use positive integers.

Step 1: Writing the Function

--

--

Max N
Max N

Written by Max N

A writer that writes about JavaScript and Python to beginners. If you find my articles helpful, feel free to follow.

No responses yet