You haven't called the function!

def test(foundN):
    if foundN%2 == 0:
        print "The number ", foundN, "is ok."
    else:
        print "Try another number. "

foundN = input("Enter number: ")
test(foundN)
Answer from Ry- on Stack Overflow
Discussions

python - Find the division remainder of a number - Stack Overflow
Note that the modulo operator always ... would expect when talking about the remainder: -10 % 3 == 2. However a/b*b + a%b == a still holds true, since python always rounds towards -Infinity, unlike some other languages, which round towards 0 but would return -1.... More on stackoverflow.com
๐ŸŒ stackoverflow.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
๐ŸŒ r/learnpython
19
7
June 26, 2024
How does 'if (number % 2 == 0)' work in this example?
โœจ Earn college credits in Cybersecurity, JS, HTML, CSS and Python ... def even_odd(number): if (number % 2 == 0): # <------ how does this work, what happens here? Check if the remainder of number 2 becomes zero? More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
2
March 29, 2017
python - Python3 division: return int when there's no remainder and a float when there is a remainder? - Stack Overflow
In python3, integer division works differently than in python 2.7.3. Is there a way to ensure that a number that doesn't have a remainder after division is returned as an int, while a number that d... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Python Central
pythoncentral.io โ€บ using-python-to-check-for-odd-or-even-numbers
Using Python to Check for Even Numbers | Python Central
February 23, 2017 - To do this, you need to use the ... the remainder of the first number divided by the second number. If the second number goes into the first evenly, then there is no remainder and the calculated answer is 0......
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_math_remainder.asp
Python math.remainder() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... # Import math Library import math # Return the remainder of x/y print (math.remainder(9, 2)) print (math.remainder(9, 3)) print (math.remainder(18, 4)) Try it Yourself ยป
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ what-is-a-modulo-operator-in-python
Modulo operator (%) in Python - GeeksforGeeks
December 20, 2025 - One of the most common uses of the modulo operator is to check whether a number is even or odd. A number is even if it leaves a remainder of 0 when divided by 2.
๐ŸŒ
Real Python
realpython.com โ€บ python-modulo-operator
Python Modulo Operator (%): How to Use Mod in Python โ€“ Real Python
April 1, 2023 - That said, you should avoid comparing the result of a modulo operation with 1 as not all modulo operations in Python will return the same remainder. ... In the second example, the remainder takes the sign of the negative divisor and returns -1. In this case, the Boolean check 3 % -2 == 1 would return False. However, if you compare the modulo operation with 0, then it doesnโ€™t matter which operand is negative.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ python modulo operator
Python Modulo Operator: Examples, Uses and Importances
June 6, 2024 - Explanation: In the above example, x = 5 , y =2, so 5 % 2 , 2 goes into 5 twice, yielding 4, so the remainder is 5 โ€“ 4 = 1. To obtain the remainder in Python, you can use the numpy.remainder() function found in the numpy package.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ how to use the python modulo operator
How to Use the Python Modulo Operator | Career Karma
December 1, 2023 - The modulo operator is placed between two numbers. In the above example, we assign the result of our sum to the Python variable โ€œexampleโ€. If there is no remainder after dividing the first number by the second, the modulo operator will return 0.
๐ŸŒ
Linuxize
linuxize.com โ€บ home โ€บ python โ€บ python modulo operator
Python Modulo Operator | Linuxize
June 16, 2020 - For example, 5 divided by 3 equals 1, with a remainder of 2, and 8 divided by 4 equals 2, with a remainder of 0. In Python, the modulo operator is represented by the percent sign (%). The syntax is as follows: ... When formatting strings, the % character represents the interpolation operator. One of the common use cases of the modulo operator is to check whether a number is odd or even.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ please help me with this code.
r/learnpython on Reddit: Please help me with this code.
June 26, 2024 -

I have been trying to make a code for divisions that outputs if your 2 numbers are divisible or if they have a remainder. I need to add an error system to make it output "ERROR" if the user inputs 0 but whenever i input zero for the 1 number the code malfunctions, this is the code: i use python in visual studio code.

def division (num_1, num_2):
    num_1 = int(input("Please enter the number to divide by: "))
    num_2 = int(input("Please enter the number to divide: "))

    division = num_2 / num_1
    remainder = num_2 % num_1
    if num_2 == (0): 
        print("ERROR!")
    elif num_1 == (0):
        print("ERROR!")
    elif remainder:
        print(f"{num_2} is not divisable by {num_1}, there is a remainder of {remainder}.")
    else:
        print(f"{num_2} is divisable by {num_1}")
Top answer
1 of 4
7
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.
2 of 4
2
There are multiple problems with your code: def division (num_1, num_2): num_1 = int(input("Please enter the number to divide by: ")) num_2 = int(input("Please enter the number to divide: ")) Your code must be called with two arguments, (num_1, num_2), but then you immediately discard those values and replace them with user input. 2. if num_2 == (0): Should be: if num_2 == 0: Similarly for: elif num_1 == (0): 3. It would be better to use divmod() Edit: If you really need to use division at all. (See the other comments below). 4. You need to either: Check for zero before attempting to divide (division by zero is an error) Use try / except to catch the ZeroDivisionError exception.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ modulo-operator-python
Modulo Operator in Python: Understanding Key Concepts | DataCamp
March 12, 2025 - This ensures that the result is always between 0 and b (exclusive) when b is positive, or between b and 0 (exclusive) when b is negative. The modulo operator (%) in Python calculates the remainder of a division operation.
๐ŸŒ
Python
mail.python.org โ€บ pipermail โ€บ tutor โ€บ 2007-May โ€บ 054282.html
[Tutor] How to test for a remainder from division
May 14, 2007 - > Matt > Matt: I'm not sure about your pseudocode, but have you tried to accomplish this with the modulus operator? It provides the remainder of integer division (i.e. a remainder of 0 indicates a perfect divisor.) so you could do: if year % 4 or year % 100 or year % 400: #then it's divisible ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-check-if-a-number-is-divisible-by-another-in-python-559547
How to Check If a Number Is Divisible by Another in Python | LabEx
In Python, we can check for divisibility using the modulo operator (%). The modulo operator returns the remainder of a division. If the remainder is 0, it means the number is divisible.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ modulo-operator
Mimo: The coding platform you need to learn Web Development, Python, and more.
Thatโ€™s where string formatting helps, especially when printing remainders in messages: ... Python's result keeps the sign of the divisor. Always test with negative inputs to avoid logical bugs. The modulo operator is highly optimized and runs in constant time (O(1)) for standard numeric types. It has negligible overhead, making it ideal for tight loops, real-time computations, and systems that require fast condition checks.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-program-to-find-the-quotient-and-remainder-of-two-numbers
Python Program to find the Quotient and Remainder of two numbers - GeeksforGeeks
July 31, 2022 - The naive approach is to find the quotient using the double division (//) operator and remainder using the modulus (%) operator. ... # Python program to find the # quotient and remainder def find(n, m): # for quotient q = n//m print("Quotient: ", q) # for remainder r = n%m print("Remainder", r) # Driver Code find(10, 3) find(99, 5)