The fractional_part function divides the numerator by the denominator, and returns just the fractional part (a number between 0 and 1). Complete the body of the function so that it returns the right number. Note: Since division by 0 produces an error, if the denominator is 0, the function should return 0 instead of attempting the division.

Respuesta :

Answer:

def fractional_part(numerator,denominator):

  if denominator == 0:

      return 0

  else :

      return (numerator/denominator)%1

Explanation:

ijeggs

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

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.
ACCESS MORE