you are looking for the modulo operator:
a % b
for example:
>>> 26 % 7
5
Of course, maybe they wanted you to implement it yourself, which wouldn't be too difficult either.
Answer from Uku Loskit on Stack Overflow Top answer 1 of 13
291
you are looking for the modulo operator:
a % b
for example:
>>> 26 % 7
5
Of course, maybe they wanted you to implement it yourself, which wouldn't be too difficult either.
2 of 13
245
The remainder of a division can be discovered using the operator %:
>>> 26%7
5
In case you need both the quotient and the modulo, there's the builtin divmod function:
>>> seconds= 137
>>> minutes, seconds= divmod(seconds, 60)
Runestone Academy
runestone.academy โบ ns โบ books โบ published โบ thinkcspy โบ SimplePythonData โบ OperatorsandOperands.html
2.7. Operators and Operands โ How to Think like a Computer Scientist: Interactive Edition
If youโre working with expressions where you need floating point values, use the division operator /. If you want an integer result, use //. The modulus operator, sometimes also called the remainder operator or integer remainder operator works on integers (and integer expressions) and yields ...
How to make Python correctly divide?
How to make Python correctly divide ??? It issues -29 // 5 = - 6 ??? and it should be - 5 !!! It issues -29 % 5 = 1 ??? and it should be - 4 !!! More on discuss.python.org
Why Python's Integer Division Floors
I point I found rather funny... In mathematical number theory, mathematicians always prefer the latter choice (floor). isn't right (it even says so in the linked Wikipedia article). Number Theorists tend use the method where a mod b gives the least nonnegative representative. More on reddit.com
Is there any reason to have integer division?
Integer division is generally a native operation on modern CPUs. To the extent that a programming language is meant to allow programmers to tell a computer what to do, this seems self-defeating. Casting to floats then dividing then casting back may be less efficient than integer divsion. The two operations are not numerically equivalent as information is lost when casting a N-bit int to an N-bit float as the significand will necessarily be smaller than the int to make room for the exponent and sign bit fields. More on reddit.com
Please help me with this code.
Well, first of all, you need to perform the test to see if the user has input 0 for the divisor (the number to divide by) before you attempt the division. Otherwise, you'll hit an error. Fortunately, you can do this by simply rearranging your code. Also, you're defining your dividend and divisor within your function; you don't need to send them as parameters to the function. This, for example, ought to work (note the lack of a def header): num_1 = int(input("Please enter the number to divide by: ")) num_2 = int(input("Please enter the number to divide: ")) if num_1 == 0: print('ERROR! Division by zero is undefined.') elif num_2 == 0: print('Zero divided by anything is zero.') else: remainder = num_2 % num_1 if remainder: print(f"{num_2} is not divisible by {num_1}, there is a remainder of {remainder}.") else: print(f"{num_2} is divisible by {num_1}") NOTE: Edited to address spelling error. More on reddit.com
Videos
03:17
Python Integer division and Remainders - YouTube
06:20
Python Tutorial #5: Python Division: /, //, and % ๐ - YouTube
04:04
math basics - integer division (Python) - YouTube
05:20
Python Programming: Exploring Integer Division and Operators - YouTube
Python Integers vs Floats - Visually Explained
Python Division and the Modulo Operator to get the ...
Hyperskill
hyperskill.org โบ university โบ python โบ integer-division-operator-in-python
Integer Division Operator in Python
December 25, 2025 - In Python, integer division, also referred to as floor division, involves discarding the remainder and returning the whole number part of the quotient. To perform division, in Python, you use two slashes (//). For instance, if you wish to divide two numbers and get the part of the outcome, ...
Enterprise DNA
blog.enterprisedna.co โบ how-to-divide-in-python-easy-examples
How to Divide in Python: Easy Examples โ Master Data Skills + AI
To perform division in Python, you can either use the single forward slash(/) for float division, or the double forward slash for integer division. You can also use NumPyโs library built-in function np.divide when dividing one array by the other. Furthermore, the % operator returns the remainder ...
GeeksforGeeks
geeksforgeeks.org โบ division-operators-in-python
Division Operators in Python - GeeksforGeeks
There are two types of division operators: Float divisionInteger division( Floor division)When an in ... Modulo operator (%) in Python gives the remainder when one number is divided by another. Python allows both integers and floats as operands, ...
Published ย April 25, 2025
Python.org
discuss.python.org โบ python help
How to make Python correctly divide? - Python Help - Discussions on Python.org
September 9, 2021 - How to make Python correctly divide ??? It issues -29 // 5 = - 6 ??? and it should be - 5 !!! It issues -29 % 5 = 1 ??? and it should be - 4 !!!
Quora
quora.com โบ How-do-you-find-the-division-and-remainder-in-Python
How to find the division and remainder in Python - Quora
Answer (1 of 3): The following are the operators: 1. โ/โ : normal division : 2. 1. this is used to divide a number by another another number and the result is obtained in floating format 2. syntax : x/y : returns the value of x divided by y in a decimal value of 15 digits after decimal 3. โ//โ...
PYnative
pynative.com โบ home โบ python โบ programs and examples โบ python programs to find quotient and remainder
Python Find Quotient and Remainder [3 Ways] โ PYnative
March 27, 2025 - In Python, you can find the quotient and remainder using the Quotient Divison (//) and Modulo (%) operator, respectively. Quotient Divison (//): This operator in Python is also called the Floor Division or Integer Division operator. It divides two numbers and returns the integer division, i.e., ...
LearnDataSci
learndatasci.com โบ solutions โบ python-double-slash-operator-floor-division
Python Double Slash (//) Operator: Floor Division โ LearnDataSci
Looking at the result of regular division when both numbers are positive, $\frac{15}{4}=3.75$, floor division returns $3$, since it's the largest integer less than or equal to $3.75$. When one of the operands is negative, the result of normal division is negative ($-3.75$), so the largest integer ...
Reddit
reddit.com โบ r/programminglanguages โบ why python's integer division floors
r/ProgrammingLanguages on Reddit: Why Python's Integer Division Floors
February 16, 2024 - Floored division produces remainders whose sign is the same as the divisor. The Wikipedia article (cited in the blog post too) has some nice graphics to show it. https://en.m.wikipedia.org/wiki/Modulo ... BTW, the >> operator of a signed integer by an integer n is equivalent to flooring division by 2**n . That is because the shifted-out bits are just discarded, without doing any rounding. This is not just to Python...
DataCamp
datacamp.com โบ tutorial โบ modulo-operator-python
Modulo Operator in Python: Understanding Key Concepts | DataCamp
March 12, 2025 - If you're new to Python, consider taking our Introduction to Python course. The modulo operator (%) computes the remainder of the division between two numbers. Given two numbers a (dividend) and b (divisor), the modulo operation returns the remainder when a is divided by b. Modulo has its roots ...
Python Morsels
pythonmorsels.com โบ integer-division
What does // mean in Python? - Python Morsels
October 17, 2022 - For most uses of division in Python, ... in rare moments when you want floor division (a.k.a. integer division) you'll want the // operator....