Python is a high level programming language that has a range of built-in modules and functions. The math
module provides methods to perform mathematical operations in a straightforward manner. One operation is finding the modulo of two numbers, which is performed by math.fmod()
. A modulo is the remainder left when a number is divided by another number.
math.fmod(x, y)
x
: A number (positive or negative) to divide. This parameter is required.y
: A number (positive or negative) to divide by x
. This parameter is required.This function returns a float
value that represents the remainder of x
and y
. A ValueError
is returned if both x
and y
are zero. The same error is returned when y
is zero, but not when x
is zero. A TypeError
is returned if x
or y
are not numbers.
#import libraryimport math#display remainders of x and yprint('10 % 4:',math.fmod(10, 4))print('200 % 5:',math.fmod(200, 5))print('-17 % 3:',math.fmod(-17, 3))print('15 % -4:',math.fmod(15, -4))print('0 % 7:',math.fmod(0, 7))print('0 % -5:',math.fmod(0, -5))print('34 % -7:',math.fmod(34, -7))print('18 % 4:',math.fmod(18, 4))