Computer Science, asked by diksha11thakur, 9 months ago

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.

Answers

Answered by nishantmehta12057
15

Answer:

def fractional_part(numerator, denominator):

# Operate with numerator and denominator to

# keep just the fractional part of the quotient

return 0```

print(fractional_part(5, 5)) # Should be 0

print(fractional_part(5, 4)) # Should be 0.25

print(fractional_part(5, 3)) # Should be 0.66...

print(fractional_part(5, 2)) # Should be 0.5

print(fractional_part(5, 0)) # Should be 0

print(fractional_part(0, 5)) # Should be 0

hope it's help you

Answered by Keerthana2812
54

Answer:

def fractional_part(numerator, denominator):

 

   if denominator >0:

         return (numerator%denominator)/denominator

   return 0

print(fractional_part(5, 5)) # Should be 0

print(fractional_part(5, 4)) # Should be 0.25

print(fractional_part(5, 3)) # Should be 0.66...

print(fractional_part(5, 2)) # Should be 0.5

print(fractional_part(5, 0)) # Should be 0

print(fractional_part(0, 5)) # Should be 0

Explanation:

Similar questions