Answer:
import math
def fractional_part(num, den):
if den == 0:
return 0
return num / den - math.floor(num / den)
print(fractional_part(5,4)) // outputs 0.25
print(fractional_part(6,4)) // outputs 0.5
print(fractional_part(12,0)) // outputs 0
Step-by-step explanation:
- Using Python Programming Language:
- Import math (Enables the use of the math.floor function)
- Create an if statement to handle situations of denominator equals to zero
- Dividing the floor (lower bound) of the numerator (num) by the denominator (den) and subtracting from the value of num / den gives the fractional part.