Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created January 31, 2022 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/2259f6a25fe6726f1c09aaf5d8e2bd71 to your computer and use it in GitHub Desktop.
Save ycui1/2259f6a25fe6726f1c09aaf5d8e2bd71 to your computer and use it in GitHub Desktop.
def quotient(dividend, divisor, taking_int=False):
"""
Calculate the product of two numbers with a base factor.
:param dividend: int | float, the dividend in the division
:param divisor: int | float, the divisor in the division
:param taking_int: bool, whether only taking the integer part of the quotient;
default: False, which calculates the precise quotient of the two numbers
:return: float | int, the quotient of the dividend and divisor
:raises: ZeroDivisionError, when the divisor is 0
"""
if divisor == 0:
raise ZeroDivisionError("division by zero")
result = dividend / divisor
if taking_int:
result = int(result)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment